cross | offset! | x | |
distance | on_line? | x= | |
distance_to_line | on_plane? | y | |
distance_to_plane | project_to_line | y= | |
dot | project_to_plane | z | |
normalize | transform | z= | |
normalize! | transform! | ||
offset | vector_to |
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
The cross method is used to compute the cross product between two vectors.
Arguments:
Returns:
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.
Arguments:
Returns:
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 the Geom module for how to create a line.
Arguments:
Returns:
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. See the Geom module for instructions on how to create a plane.
Arguments:
Returns:
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.
Arguments:
Returns:
vector = Geom::Vector3d.new 0,1,0 a = [1,0,0] d = a.dot vector
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:
# Compute a 1" long vector from a 2" long vector. a = [0,0,2] v = a.normalize! puts "Normalized vector: " + v.join(",")
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:
# Change a 2" long vector to a 1" long vector. a = [0,0,2] a.normalize! puts "Normalized vector: " + a.join(",")
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:
Returns:
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. The array is modified in place.
Arguments:
Returns:
a = [10,10,10] vector = Geom::Vector3d.new(0,0,1) a.offset! vector
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:
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 SketchUp's standard floating point tolerance).
See the Geom module for instructions on how to create a plane.
Arguments:
Returns:
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. See the Geom module for how to create a line.
Arguments:
Returns:
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.
See the Geom module for instructions on how to create a plane.
Arguments:
Returns:
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 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:
Returns:
point2 = Geom::Point3d.new 100,200,300 my_transform = Geom::Transformation.new(point2) a = [10,10,10] point3 = a.transform my_transform
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:
Returns:
point2 = Geom::Point3d.new 100,200,300 my_transform = Geom::Transformation.new(point2) a = [10,10,10] a.transform! my_transform
The vector_to method is used to create an array as a vector from one point to a second point.
Arguments:
Returns:
point2 = Geom::Point3d.new 100,200,300 a = [10,10,10] vector = a.vector_to point2
The x method retrieves the x coordinate.
Returns:
a = [1,2,3] x = a.x
The x= method sets the x coordinate.
Arguments:
Returns:
a = [1,2,3] a.x = 5
The y method retrieves the y coordinate.
Returns:
a = [1,2,3] y = a.y
The y= method sets the y coordinate.
Arguments:
Returns:
a = [1,2,3] a.y = 5
The z method retrieves the z coordinate.
Returns:
a = [1,2,3] z = a.z
The z= method sets the z coordinate.
Arguments:
Returns:
a = [1,2,3] a.z = 5