Home
Developer Docs

Array

SketchUp 6.0+

class

Parent: Object

Introduction

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 Vector3d or Point3d object (which can be thought of as arrays of 3 coordinate values). Therefore, you can use the Array class in place of a Point3d or Vector3d as a way to pass coordinate values.

     # 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)

Methods

Array.crossSketchUp 6.0+

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

Arguments:

vector
The Vector object used to compute the cross product.

Returns:

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

Array.distanceSketchUp 6.0+

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

Arguments:

point
The Point3d object used to compute the distance.

Returns:

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

Array.distance_to_lineSketchUp 6.0+

The distance_to_line method is used to compute the distance from a Point3d object to a line. Lines are defined by an array of a point and a vector or an array of two points. See the Geom module for how to create a line.

Arguments:

line
An array with a Point3d object and a Vector3d object if successful. See the Geom module for further information on lines.

Returns:

The distance if successful
 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)

Array.distance_to_planeSketchUp 6.0+

The distance_to_plane method is used to compute the distance from a Point3d object to a plane. See the Geom module for instructions on how to create a plane.

Arguments:

plane
A plane used to compute the distance. See the Geom module description for further information on planes.

Returns:

The distance if successful
 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)

Array.dotSketchUp 6.0+

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

Arguments:

vector
A Vector3d object used to compute the dot product.

Returns:

The dot product if successful
 vector = Geom::Vector3d.new(0, 1, 0)
 array = [1, 0, 0]
 # This will return a Float, in this case 22.0
 dot_product = array.dot(vector)

Array.normalizeSketchUp 6.0+

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.

The arguments and return value will be converted to a floating point value (unlike in the Vector3d.normalize!).

Returns:

An array object representing a vector if successful
 array = [1, 2, 3]
 # This will return a new Vector3d
 normal_vector = array.normalize

Array.normalize!SketchUp 6.0+

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

Returns:

A Vector3d object if successful
 array = [1, 2, 3]
 # This will modify 'array' in place
 array.normalize!

Array.offsetSketchUp 6.0+

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

Arguments:

vector1
A Vector3d object used to offset the point.

Returns:

The newly offset point or vector.
 array = [10, 10, 10]
 vector = Geom::Vector3d.new(0, 0, 1)
 # This will return a new Array
 point = array.offset(vector)

Array.offset!SketchUp 6.0+

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

Arguments:

vector1
A Vector3d object used to offset the point.

Returns:

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

Array.on_line?SketchUp 6.0+

The on_line? method is used to determine if a Point3d object is on a line. See the Geom module for how to create a line.

Returns:

true if the point is on the line, false if the on_plane is not on the line.
 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)

Array.on_plane?SketchUp 6.0+

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

See the Geom module for instructions on how to create a plane.

Arguments:

plane
The plane to check against the Point3d represented by the Array.

Returns:

true if successful, false if unsuccessful.
 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)

Array.project_to_lineSketchUp 6.0+

The project_to_line method is used to retrieve the projection of a Point3d object onto a line. See the Geom module for how to create a line.

Arguments:

line
An array with a Point3d object and a Vector3d object.

Returns:

A new Point3d object that is the point on the line that is closest to this point (if successful)
 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)

Array.project_to_planeSketchUp 6.0+

The project_to_plane method retrieves the projection of a Point3d object onto a plane.

See the Geom module for instructions on how to create a plane.

Arguments:

plane
The plane used to determine the projection from.

Returns:

A new Point3d object that is the point on the plane that is closest to this plane (if successful)
 plane = [Geom::Point3d.new(0, 0, 0), Geom::Vector3d.new(0, 0, 1)]
 array = [10, 10, 10]
 # This will return a new Array
 point_on_plane = array.project_to_plane(plane)

Array.transformSketchUp 6.0+

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

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

Arguments:

transform
A Transformation object.

Returns:

The newly transformed point.
 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)

Array.transform!SketchUp 6.0+

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

This method modifies the original.

Arguments:

transform
A Transformation object.

Returns:

The newly transformed point.
 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)

Array.vector_toSketchUp 6.0+

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

Arguments:

point
A Point3d object representing the second point.

Returns:

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

Array.xSketchUp 6.0+

The x method retrieves the x coordinate.

Returns:

The x coordinate if successful
 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

Array.x=SketchUp 6.0+

The x= method sets the x coordinate.

Arguments:

x
The new x position.

Returns:

The new x coordinate if successful
 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

Array.ySketchUp 6.0+

The y method retrieves the y coordinate.

Returns:

The y coordinate if successful
 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

Array.y=SketchUp 6.0+

The y= method sets the y coordinate.

Arguments:

y
The new y position.

Returns:

The new y coordinate if successful
 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

Array.zSketchUp 6.0+

The z method retrieves the z coordinate.

Returns:

The z coordinate if successful
 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

Array.z=SketchUp 6.0+

The z= method sets the z coordinate.

Arguments:

z
The new z position.

Returns:

The new z coordinate if successful
 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

  

Trimble Home
About Trimble - Privacy Policy - Contact Us