Array

class Array

Parent: Object | Class Index
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
a = [1,0,0]
v = a.cross vector
if (v)
UI.messagebox v
else
UI.messagebox "Failure"
end

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 a = [1,1,1] distance = a.distance point1

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)] a = [10,10,10] distance = a.distance_to_line line

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)] a = [10,10,10] distance = a.distance_to_plane plane

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 a = [1,0,0] d = a.dot vector

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] v = a.normalize

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] v = a.normalize!

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] vector = Geom::Vector3d.new(0,0,1) point2 = a.offset vector

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] vector = Geom::Vector3d.new(0,0,1) point2 = a.offset! vector

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)] a = [10,10,10] status = a.on_line? line

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)] a = [10,10,10] status = a.on_plane? plane

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

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

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 = Geom::Transformation.new(point2) a = [10,10,10] point3 = a.transform transform

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 transform = Geom::Transformation.new(point2) a = [10,10,10] point3 = a.transform! transform

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 a = [10,10,10] vector = a.vector_to point2

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 = a.x

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] x = a.x=2

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 = a.y

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] y = a.y=2

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 = a.z

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] z = a.z=2