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.
     my_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.)
     my_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
     cp = entities.add_cpoint my_array

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

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:

vector2
a Vector3d object if successful
 vector = Geom::Vector3d.new 0,1,0
 a = [1,0,0]
 v = a.cross vector
 if (v)
   UI.messagebox v
 else
   UI.messagebox "Failure"
 end

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:

distance
the distance if successful
 point1 = Geom::Point3d.new 10,10,10
 a = [1,1,1]
 distance = a.distance point1

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:

distance
the distance if successful
 line = [Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1)]
 a = [10,10,10]
 distance = a.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:

distance
the distance if successful
 plane = [Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1)]
 a = [10,10,10]
 distance = a.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:

dot
the dot product if successful
 vector = Geom::Vector3d.new 0,1,0
 a = [1,0,0]
 d = a.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:

vector
a Vector3d object if successful
 # Compute a 1" long vector from a 2" long vector.
 a = [0,0,2]
 v = a.normalize!
 puts "Normalized vector: " + v.join(",")

Array.normalize!SketchUp 6.0+

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

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

Returns:

vector
a Vector3d object if successful
 # Change a 2" long vector to a 1" long vector.
 a = [0,0,2]
 a.normalize!
 puts "Normalized vector: " + a.join(",")

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:

array
the newly offset point or vector.
 a = [10,10,10]
 vector = Geom::Vector3d.new(0,0,1)
 point2 = a.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:

array
the newly offset point or vector.
 a = [10,10,10]
 vector = Geom::Vector3d.new(0,0,1)
 a.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:

status
true if the point is on the line, false if the point is not on the line.
 line = [Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1)]
 a = [10,10,10]
 status = a.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:

success
true if successful, false if unsuccessful.
 plane = [Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1)]
 a = [10,10,10]
 status = a.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:

point
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)]
 a = [10,10,10]
 pointonline = a.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:

point
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)]
 a = [10,10,10]
 pointonplane = a.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:

point
the newly transformed point.
 point2 = Geom::Point3d.new 100,200,300
 my_transform = Geom::Transformation.new(point2)
 a = [10,10,10]
 point3 = a.transform my_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:

point
the newly transformed point.
 point2 = Geom::Point3d.new 100,200,300
 my_transform = Geom::Transformation.new(point2)
 a = [10,10,10]
 a.transform! my_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:

vector
a Vector3d object if successful
 point2 = Geom::Point3d.new 100,200,300
 a = [10,10,10]
 vector = a.vector_to point2

Array.xSketchUp 6.0+

The x method retrieves the x coordinate.

Returns:

x
the x coordinate if successful
 a = [1,2,3]
 x = a.x

Array.x=SketchUp 6.0+

The x= method sets the x coordinate.

Arguments:

x
The new x position.

Returns:

x
the new x coordinate if successful
 a = [1,2,3]
 a.x = 5

Array.ySketchUp 6.0+

The y method retrieves the y coordinate.

Returns:

y
the y coordinate if successful
 a = [1,2,3]
 y = a.y

Array.y=SketchUp 6.0+

The y= method sets the y coordinate.

Arguments:

y
The new y position.

Returns:

y
the new y coordinate if successful
 a = [1,2,3]
 a.y = 5

Array.zSketchUp 6.0+

The z method retrieves the z coordinate.

Returns:

z
the z coordinate if successful
 a = [1,2,3]
 z = a.z

Array.z=SketchUp 6.0+

The z= method sets the z coordinate.

Arguments:

z
The new z position.

Returns:

z
the new z coordinate if successful
 a = [1,2,3]
 a.z = 5

  

Trimble Home
About Trimble - Privacy Policy - Contact Us