class Array |
Parent: Object |
|
Methods:cross,distance, distance_to_line, distance_to_plane, dot, normalize, normalize!, offset, offset!, on_line?, on_plane?,project_to_line, project_to_plane,transform, transform!, vector_to, x, x=, y, y=, z, z= |
|
Sample Code: arraytests.rb |
|
The SketchUp Array class adds additional methods to the standard Ruby Array class. Namely the SketchUp Ruby Array class contains methods allowing an array to behave just as Vector3d or Point3d objects (which are 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.
Instance Methods |
cross |
The cross method is used to compute the cross product between two vectors. |
Syntax: |
vector2 = array.cross vector |
Arguments: |
vector - the Vector object used to compute the cross product |
Return Value: |
vector2- a Vector3d object if successful |
Comments: |
|
Example: |
vector = Geom::Vector3d.new 0,1,0 |
distance |
The distance method is used to compute the distance between two points. |
Syntax: |
distance = array.distance point |
Arguments: |
point - the Point3d object used to compute the distance |
Return Value: |
distance - the distance if successful |
Comments: |
|
Example: |
point1 = Geom::Point3d.new 10,10,10 |
distance_to_line |
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 also the Geom class. |
Syntax: |
distance = array.distance_to_line line |
Arguments: |
line - an array with a Point3d object and a Vector3d object if successful. See the Geom class for further information on lines. |
Return Value: |
distance - the distance if successful |
Comments: |
|
Example: |
line = [Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1)] |
distance_to_plane |
The distance_to_plane method is used to compute the distance from a Point3d object to a plane. |
Syntax: |
distance = array.distance_to_plane plane |
Arguments: |
plane - a plane used to compute the distance. See the Geom class for further information on planes. |
Return Value: |
distance - the distance if successful |
Comments: |
|
Example: |
plane = [Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1)] |
dot |
The dot method is used to compute the dot product between two vectors |
Syntax: |
dot = array.dot vector |
Arguments: |
vector - a Vector3d object used to compute the dot product |
Return Value: |
dot - the dot product if successful |
Comments: |
|
Example: |
vector = Geom::Vector3d.new 0,1,0 |
normalize |
The normalize method is used to retrieve a new Vector3d object which is a unit vector in the same direction as this vector. |
Syntax: |
vector = array.normalize |
Arguments: |
|
Return Value: |
vector - a Vector3d object if successful |
Comments: |
The arguments and return value will be converted to a floating point value (unlike in the Vector3d.normalize).
|
Example: |
a = [0,0,1] |
normalize! |
The normalize! method is used to normalize a vector in place (setting its length to 1). |
Syntax: |
vector = array.normalize! |
Arguments: |
|
Return Value: |
vector - a Vector3d object if successful |
Comments: |
The arguments and return value will be converted to a floating point value (unlike in the Vector3d.normalize!). |
Example: |
a
= [0,0,1] |
offset |
The offset method offsets a point by a vector and returns a new point. |
Syntax: |
vector2 = array.offset vector1 |
Arguments: |
vector1 - a Vector3d object used to offset the point |
Return Value: |
vector2 - a Vector3d object if successful |
Comments: |
|
Example: |
a =[10,10,10] |
offset! |
The offset method is used to offset a point by a vector. |
Syntax: |
status = array.offset! vector |
Arguments: |
vector1 - a Vector3d object used to offset the point |
Return Value: |
status - |
Comments: |
|
Example: |
a = [10,10,10] |
on_line? |
The on_line? method is used to determine if a Point3d object is on a line |
Syntax: |
status = array.online? |
Arguments: |
|
Return Value: |
status - true if the point is on the line, false if the point is not on the line. |
Comments: |
|
Example: |
line = [Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1)] |
on_plane? |
The on_plane? method is used to determine if a Point3d object is on a plane (to within tolerance). |
Syntax: |
success - array.on_plane? plane |
Arguments: |
plane - the plane of the Point3d |
Return Value: |
success - true if successful, false if unsuccessful. |
Comments: |
See the Geom module for instructions on how to create a plane. |
Example: |
plane = [Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1)] |
project_to_line |
The project_to_line method is used to retrieve the projection of a Point3d object onto a line. |
Syntax: |
point = array.project_to_line line |
Arguments: |
line - an array with a Point3d object and a Vector3d object. |
Return Value: |
point - a new Point3d object that is the point on the line that is closest to this point (if successful) |
Comments: |
|
Example: |
line = [Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1)] |
project_to_plane |
The project_to_plane method retrieves the projection of a Point3d object onto a plane. |
Syntax: |
point = array.project_to_plane plane |
Arguments: |
plane - the plane used to determine the projection from |
Return Value: |
point - a new Point3d object that is the point on the plane that is closest to this plane (if successful) |
Comments: |
See the Geom module for instructions on how to create a plane. |
Example: |
plane = [Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1)] |
transform |
The transform method is used to create a new Array object by transforming this Array object as a point |
Syntax: |
array = array.transform transformation |
Arguments: |
transformation - a Transformation object |
Return Value: |
array - an Array object if successful |
Comments: |
|
Example: |
point2 = Geom::Point3d.new 100,200,300 |
transform! |
The transform! method is used to apply a Transformation object to a Point3d object defined by an Array object. |
Syntax: |
status = array.transform! transformation |
Arguments: |
transformation - a Transformation object |
Return Value: |
status - |
Comments: |
This method modifies the Point3d object |
Example: |
point2 = Geom::Point3d.new 100,200,300 |
vector_to |
The transform! method is used to create an array as a vector from one point to a second point. |
Syntax: |
vector = array.vector_to point |
Arguments: |
point - a Point3d object representing the second point |
Return Value: |
vector - a Vector3d object if successful |
Comments: |
|
Example: |
point2 = Geom::Point3d.new 100,200,300 |
X |
The x method retrieves the x coordinate. |
Syntax: |
x = array.x |
Arguments: |
|
Return Value: |
x - the x coordinate if successful |
Comments: |
|
Example: |
a = [1,2,3] |
X= |
The x= method is used to set the x coordinate. |
Syntax: |
x= array.x = x |
Arguments: |
x - the new x coordinate |
Return Value: |
|
Comments: |
|
Example: |
a = [1,2,3] |
Y |
The y method is used to get the y coordinate. |
Syntax: |
y = array.y |
Arguments: |
|
Return Value: |
y - the y coordinate if successful |
Comments: |
|
Example: |
a = [1,2,3] |
Y= |
The y= method is used to get the y coordinate. |
Syntax: |
y=array.y = y |
Arguments: |
y - the new y coordinate |
Return Value: |
|
Comments: |
|
Example: |
a = [1,2,3] |
Z |
The z method is used to get the z coordinate. |
Syntax: |
z = array.z |
Arguments: |
|
Return Value: |
z - the z coordinate if successful |
Comments: |
|
Example: |
a = [1,2,3] |
Z= |
The z= method is used to set the z coordinate. |
Syntax: |
x= array.z = z |
Arguments: |
z - the new z coordinate |
Return Value: |
|
Comments: |
|
Example: |
a = [1,2,3] |