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