123456789_123456789_123456789_123456789_123456789_

Class: Array

Relationships
Inherits: Object

Overview

The SketchUp Array class adds additional methods to the standard Ruby Array class. Specifically, it contains methods allowing an array to behave just as a ::Geom::Vector3d or ::Geom::Point3d object (which can be thought of as arrays of 3 coordinate values). Therefore, you can use the Array class in place of a ::Geom::Point3d or ::Geom::Vector3d as a way to pass coordinate values.

Examples:

# An array of 3 values can represent a 1" long vector pointing straight
# up in the z-direction.
array = [0, 0, 1]

# An array of 3 values can also represent a point 1" above the origin in
# the z direction. (Note that this is the exact same array.)
array = [0, 0, 1]

# How it is interpreted is based on context. For example, this code will
# create a construction point at position 0, 0, 1, since in this context
# a Point3d is expected.
entities = Sketchup.active_model.entities
construction_point = entities.add_cpoint(array)

# Whereas this will move our construction point 1" upward, since in this
# context a Vector3d is expected.
transformation = Geom::Transformation.new(array)
entities.transform_entities(transformation, construction_point)

Version:

  • SketchUp 6.0

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#xObject? (rw)

The #x method retrieves the x coordinate.

Examples:

array = [1, 2, 3]
# This will return a Fixnum, in this case 1
x = array.x

array = [1.0, 2.0, 3.0]
# This will return a Float, in this case 1.0
x = array.x

Returns:

  • (Object, nil)

    The x coordinate if successful

Version:

  • SketchUp 6.0

#x=(x) ⇒ Object (rw)

The #x= method sets the x coordinate.

Examples:

array = [1, 2, 3]
# This will initialize the x value as a Float
array.x = 2.5
# This will initialize the x value as a Fixnum
array.x = 5

Parameters:

  • x (Object)

    The new x position.

Returns:

  • (Object)

    The new x coordinate if successful

Version:

  • SketchUp 6.0

#yObject? (rw)

The #y method retrieves the y coordinate.

Examples:

array = [1, 2, 3]
# This will return a Fixnum, in this case 2
y = array.y

array = [1.0, 2.0, 3.0]
# This will return a Float, in this case 2.0
y = array.y

Returns:

  • (Object, nil)

    The y coordinate if successful

Version:

  • SketchUp 6.0

#y=(y) ⇒ Object (rw)

The #y= method sets the y coordinate.

Examples:

array = [1, 2, 3]
# This will initialize the y value as a Float
array.y = 2.5
# This will initialize the y value as a Fixnum
array.y = 5

Parameters:

  • y (Object)

    The new y position.

Returns:

  • (Object)

    The new y coordinate if successful

Version:

  • SketchUp 6.0

#zObject? (rw)

The #z method retrieves the z coordinate.

Examples:

array = [1, 2, 3]
# This will return a Fixnum, in this case 3
z = array.z

array = [1.0, 2.0, 3.0]
# This will return a Float, in this case 3.0
z = array.z

Returns:

  • (Object, nil)

    The z coordinate if successful

Version:

  • SketchUp 6.0

#z=(z) ⇒ Object (rw)

The #z= method sets the z coordinate.

Examples:

array = [1, 2, 3]
# This will initialize the z value as a Float
array.z = 2.5
# This will initialize the z value as a Fixnum
array.z = 5

Parameters:

  • z (Object)

    The new z position.

Returns:

  • (Object)

    The new z coordinate if successful

Version:

  • SketchUp 6.0

Instance Method Details

#cross(vector) ⇒ Geom::Vector3d #cross(vector) ⇒ Geom::Vector2d

The #cross method is used to compute the cross product between two vectors.

Examples:

With 3d array

vector1 = Geom::Vector3d.new(0, 1, 0)
array = [1, 0, 0]
# This will return a new Vector3d
vector2 = array.cross(vector1)

With 2d array

vector1 = Geom::Vector2d.new(0, 1)
array = [1, 0]
vector2 = array.cross(vector1)

vector1 = Geom::Vector3d.new(0, 1, 0)
array = [1, 0]
vector2 = array.cross(vector1) # This will force array to be [1, 0, 0]

Overloads:

Raises:

  • ArgumentError if the argument is the wrong vector type

Version:

  • SketchUp 6.0

#distance(point) ⇒ Length #distance(point) ⇒ Length

The #distance method is used to compute the distance between two points.

Examples:

With 3d array

point = Geom::Point3d.new(10, 10, 10)
array = [1, 1, 1]
# This will return a Length
distance = array.distance(point)

With 2d array

point = Geom::Point2d.new(10, 10)
array = [1, 2]
distance = array.distance(point)

point = Geom::Point3d.new(10, 10, 10)
distance = array.distance(point)

Overloads:

Raises:

  • ArgumentError if the argument is the wrong point type

Version:

  • SketchUp 6.0

#distance_to_line(point, vector) ⇒ Length #distance_to_line(point1, point2) ⇒ Length

The #distance_to_line method is used to compute the distance from a ::Geom::Point3d object to a line.

Examples:

line = [Geom::Point3d.new(0, 0, 0), Geom::Vector3d.new(0, 0, 1)]
array = [10, 10, 10]
# This will return a Length
distance = array.distance_to_line(line)

Overloads:

See Also:

Version:

  • SketchUp 6.0

#distance_to_plane(point, vector) ⇒ Length #distance_to_plane(point1, point2, point3) ⇒ Length #distance_to_plane(float1, float2, float3, float4) ⇒ Length #distance_to_plane(array) ⇒ Length #distance_to_plane(array) ⇒ Length #distance_to_plane(array) ⇒ Length

The #distance_to_plane method is used to compute the distance from a ::Geom::Point3d object to a plane.

Examples:

plane = [Geom::Point3d.new(0, 0, 0), Geom::Vector3d.new(0, 0, 1)]
array = [10, 10, 10]
# This will return a Length
distance = array.distance_to_plane(plane)

Overloads:

  • #distance_to_plane(point, vector) ⇒ Length

    Plane defined by

    Parameters:

    Returns:

    • (Length)

      The distance between the two points.

  • #distance_to_plane(point1, point2, point3) ⇒ Length
    Note:

    The three points should not be co-linear or duplicate.

    Plane defined by three points.

    Parameters:

    Returns:

    • (Length)

      The distance between the two points.

  • #distance_to_plane(float1, float2, float3, float4) ⇒ Length

    Plane defined by its coefficents.

    Parameters:

    • float1 (Float)
    • float2 (Float)
    • float3 (Float)
    • float4 (Float)

    Returns:

    • (Length)

      The distance between the two points.

  • #distance_to_plane(array) ⇒ Length
    Note:

    The three points should not be co-linear or duplicate.

    Plane defined by three points.

    Parameters:

    Returns:

    • (Length)

      The distance between the two points.

  • #distance_to_plane(array) ⇒ Length

    Plane defined by three points.

    Parameters:

    Returns:

    • (Length)

      The distance between the two points.

  • #distance_to_plane(array) ⇒ Length

    Plane defined by its coefficents.

    Parameters:

    • point (Array<Float, Float, Float, Float>)

    Returns:

    • (Length)

      The distance between the two points.

See Also:

Version:

  • SketchUp 6.0

#dot(vector) ⇒ Float #dot(vector) ⇒ Float

The #dot method is used to compute the dot product between two vectors.

Examples:

With 3d array

vector = Geom::Vector3d.new(12, 12, 0)
array = [12, 0, 0]
# This will return a Float, in this case 144.0
dot_product = array.dot(vector)

With 2d array

vector = Geom::Vector2d.new(12, 12)
array = [12, 0]
# This will return a float
dot_product = array.dot(vector)

Overloads:

Raises:

  • ArgumentError if the argument is the wrong vector type

Version:

  • SketchUp 6.0

#normalizeArray(Float, Float, Float) #normalizeArray(Float, Float)

Note:

The arguments and return value will be converted to a floating point value. (Unlike in the Geom::Vector3d#normalize! method.)

The #normalize method is used to normalize a vector (setting its length to 1). It returns a new array rather than changing the original in place.

Examples:

With 3d array

array = [1, 2, 3]
# This will return a new Vector3d
normal_vector = array.normalize

With 2d array

array = [1, 2]
normal_vector = array.normalize

Overloads:

  • #normalizeArray(Float, Float, Float)

    Returns:

    • (Array(Float, Float, Float))

      an array object representing a vector

  • #normalizeArray(Float, Float)

    Returns:

    • (Array(Float, Float))

      an array object representing a vector

Version:

  • SketchUp 6.0

#normalize!Array(Float, Float, Float) #normalize!Array(Float, Float)

The #normalize! method is used to normalize a vector in place (setting its length to 1).

Examples:

With 3d array

array = [1, 2, 3]
# This will modify 'array' in place
array.normalize!

With 2d array

array = [1, 2]
array.normalize!

Overloads:

  • #normalize!Array(Float, Float, Float)

    Returns:

    • (Array(Float, Float, Float))

      an array object representing a vector

  • #normalize!Array(Float, Float)

    Returns:

    • (Array(Float, Float))

      an array object representing a vector

Version:

  • SketchUp 6.0

#offset(vector) ⇒ Array(Length, Length, Length) #offset(vector) ⇒ Array(Length, Length) #offset(vector, length) ⇒ Array(Length, Length, Length) #offset(vector, length) ⇒ Array(Length, Length)

The #offset method is used to offset a point by a vector. it returns a new array rather than modifying the original in place.

Examples:

With 3d array

array = [10, 10, 10]
vector = Geom::Vector3d.new(0, 0, 1)
# This will modify 'array' in place
length_array = array.offset(vector)

With 2d array

array = [10, 10]
vector = Geom::Vector2d.new(0, 1)
length_array = array.offset(vector)

# Using Vector3d with a 2d array
array = [10, 10]
vector = Geom::Vector3d.new(0, 0, 1)
length_array = array.offset(vector)

Overloads:

  • #offset(vector) ⇒ Array(Length, Length, Length)

    Parameters:

    • vector (Geom::Vector3d)

      A Vector3d object used to offset the point.

    Returns:

    • (Array(Length, Length, Length))

      The newly offset array representing a point or vector.

  • #offset(vector) ⇒ Array(Length, Length)

    Parameters:

    • vector (Geom::Vector2d)

      A Vector2d object used to offset the point.

    Returns:

    • (Array(Length, Length))

      The newly offset array representing a point or vector.

  • #offset(vector, length) ⇒ Array(Length, Length, Length)

    Parameters:

    • vector (Geom::Vector3d)

      A Vector3d object used to offset the point.

    • length (Length)

      An overriding distance for how far to offset.

    Returns:

    • (Array(Length, Length, Length))

      The newly offset array representing a point or vector.

  • #offset(vector, length) ⇒ Array(Length, Length)

    Parameters:

    • vector (Geom::Vector2d)

      A Vector2d object used to offset the point.

    • length (Length)

      An overriding distance for how far to offset.

    Returns:

    • (Array(Length, Length))

      The newly offset array representing a point or vector.

Raises:

  • ArgumentError if the argument is the wrong vector type

Version:

  • SketchUp 6.0

#offset!(vector) ⇒ Array(Length, Length, Length) #offset!(vector) ⇒ Array(Length, Length) #offset!(vector, length) ⇒ Array(Length, Length, Length) #offset!(vector, length) ⇒ Array(Length, Length)

The #offset! method is used to offset a point by a vector. The array is modified in place.

Examples:

With 3d array

array = [10, 10, 10]
vector = Geom::Vector3d.new(0, 0, 1)
# This will modify 'array' in place
array.offset!(vector)

With 2d array

array = [10, 10]
vector = Geom::Vector2d.new(0, 1)
array.offset!(vector)

# Using Vector3d with a 2d array
array = [10, 10]
vector = Geom::Vector3d.new(0, 0, 1)
array.offset!(vector)

Overloads:

  • #offset!(vector) ⇒ Array(Length, Length, Length)

    Parameters:

    • vector (Geom::Vector3d)

      A Vector3d object used to offset the point.

    Returns:

    • (Array(Length, Length, Length))

      The newly offset array representing a point or vector.

  • #offset!(vector) ⇒ Array(Length, Length)

    Parameters:

    • vector (Geom::Vector2d)

      A Vector2d object used to offset the point.

    Returns:

    • (Array(Length, Length))

      The newly offset array representing a point or vector.

  • #offset!(vector, length) ⇒ Array(Length, Length, Length)

    Parameters:

    • vector (Geom::Vector3d)

      A Vector3d object used to offset the point.

    • length (Length)

      An overriding distance for how far to offset.

    Returns:

    • (Array(Length, Length, Length))

      The newly offset array representing a point or vector.

  • #offset!(vector, length) ⇒ Array(Length, Length)

    Parameters:

    • vector (Geom::Vector2d)

      A Vector2d object used to offset the point.

    • length (Length)

      An overriding distance for how far to offset.

    Returns:

    • (Array(Length, Length))

      The newly offset array representing a point or vector.

Raises:

  • ArgumentError if the argument is the wrong vector type

Version:

  • SketchUp 6.0

#on_line?(point, vector) ⇒ Boolean #on_line?(point1, point2) ⇒ Boolean

The #on_line? method is used to determine if a ::Geom::Point3d object is on a line.

Examples:

line = [Geom::Point3d.new(0, 0, 0), Geom::Vector3d.new(0, 0, 1)]
array = [10, 10, 10]
# This will return a true or false value
on_plane = array.on_line?(line)

Overloads:

  • #on_line?(point, vector) ⇒ Boolean

    Parameters:

    Returns:

    • (Boolean)

      true if the point is on the line, false if the point is not on the line.

  • #on_line?(point1, point2) ⇒ Boolean

    Parameters:

    Returns:

    • (Boolean)

      true if the point is on the line, false if the point is not on the line.

See Also:

Version:

  • SketchUp 6.0

#on_plane?(point, vector) ⇒ Boolean #on_plane?(point1, point2, point3) ⇒ Boolean #on_plane?(float1, float2, float3, float4) ⇒ Boolean #on_plane?(array) ⇒ Boolean #on_plane?(array) ⇒ Boolean #on_plane?(array) ⇒ Boolean

The #on_plane? method is used to determine if a ::Geom::Point3d object is on a plane (to within SketchUp’s standard floating point tolerance).

Examples:

plane = [Geom::Point3d.new(0, 0, 0), Geom::Vector3d.new(0, 0, 1)]
array = [10, 10, 10]
# This will return a true or false value
on_plane = array.on_plane?(plane)

Overloads:

  • #on_plane?(point, vector) ⇒ Boolean

    Plane defined by

    Parameters:

  • #on_plane?(point1, point2, point3) ⇒ Boolean
    Note:

    The three points should not be co-linear or duplicate.

    Plane defined by three points.

    Parameters:

  • #on_plane?(float1, float2, float3, float4) ⇒ Boolean

    Plane defined by its coefficents.

    Parameters:

    • float1 (Float)
    • float2 (Float)
    • float3 (Float)
    • float4 (Float)
  • #on_plane?(array) ⇒ Boolean
    Note:

    The three points should not be co-linear or duplicate.

    Plane defined by three points.

    Parameters:

  • #on_plane?(array) ⇒ Boolean

    Plane defined by three points.

    Parameters:

  • #on_plane?(array) ⇒ Boolean

    Plane defined by its coefficents.

    Parameters:

    • point (Array<Float, Float, Float, Float>)

See Also:

Version:

  • SketchUp 6.0

#project_to_line(point, vector) ⇒ Array(Length, Length, Length) #project_to_line(point1, point2) ⇒ Array(Length, Length, Length)

The #project_to_line method is used to retrieve the projection of a ::Geom::Point3d object onto a line.

Examples:

line = [Geom::Point3d.new(0, 0, 0), Geom::Vector3d.new(0, 0, 1)]
array = [10, 10, 10]
# This will return a new Array
point_on_line = array.project_to_line(line)

Overloads:

See Also:

Version:

  • SketchUp 6.0

#project_to_plane(point, vector) ⇒ Array(Length, Length, Length) #project_to_plane(point1, point2, point3) ⇒ Array(Length, Length, Length) #project_to_plane(float1, float2, float3, float4) ⇒ Array(Length, Length, Length) #project_to_plane(array) ⇒ Array(Length, Length, Length) #project_to_plane(array) ⇒ Array(Length, Length, Length) #project_to_plane(array) ⇒ Array(Length, Length, Length)

The #project_to_plane method retrieves the projection of a ::Geom::Point3d onto a plane.

Examples:

plane = [Geom::Point3d.new(0, 0, 0), Geom::Vector3d.new(0, 0, 1)]
array = [10, 10, 10]
point_on_plane = array.project_to_plane(plane)

Overloads:

See Also:

Version:

  • SketchUp 6.0

#transform(transform) ⇒ Array<Length, Length> #transform(transform) ⇒ Array<Length, Length, Length>

The #transform method is used to apply a ::Geom::Transformation or ::Geom::Transformation2d object to a ::Geom::Point3d or ::Geom::Point2d object defined by an Array object.

This method returns a new Array object instead of modifying the original.

Examples:

point1 = Geom::Point3d.new(10, 20, 30)
transform = Geom::Transformation.new(point1)
array = [1, 2, 3]
# This will return a new Array
point2 = array.transform(transform)

Overloads:

Version:

  • SketchUp 6.0

#transform!(transform) ⇒ Array #transform!(transform) ⇒ Array

Note:

This method modifies the original.

The #transform! method is used to apply a ::Geom::Transformation object to a ::Geom::Point3d object defined by an Array object.

Examples:

point = Geom::Point3d.new(10, 20, 30)
transform = Geom::Transformation.new(point)
array = [1, 2, 3]
# This will modify 'array' in place
array.transform!(transform)

Overloads:

  • #transform!(transform) ⇒ Array

    Parameters:

    Returns:

    • (Array)

      The newly transformed point.

  • #transform!(transform) ⇒ Array

    Parameters:

    Returns:

    • (Array)

      The newly transformed point.

Version:

  • SketchUp 6.0

#vector_to(point) ⇒ Geom::Vector3d #vector_to(point) ⇒ Geom::Vector2d

The #vector_to method is used to create an array as a vector from one point to a second point.

Examples:

With 3d array

point = Geom::Point3d.new(10, 20, 30)
array = [1, 2, 3]
# This will return a new Vector3d
vector = array.vector_to(point)

With 2d array

point = Geom::Point2d.new(10, 20)
array = [1, 2]
# This will return a new Vector2d
vector = array.vector_to(point)

point = Geom::Point3d.new(10, 20)
# This will return a new Vector3d
vector = array.vector_to(point)

Overloads:

Raises:

  • ArgumentError if the argument is the wrong point type

Version:

  • SketchUp 6.0