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. 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.) 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 construction_point = entities.add_cpoint(array) # Whereas this will move our construction point 1" upward, since in this # context a Vector3d is expected. transformation = Geom::Transformation.new(array) entities.transform_entities(transformation, construction_point)
The cross method is used to compute the cross product between two vectors.
Arguments:
Returns:
vector1 = Geom::Vector3d.new(0, 1, 0) array = [1, 0, 0] # This will return a new Vector3d vector2 = array.cross(vector1)
The distance method is used to compute the distance between two points.
Arguments:
Returns:
point = Geom::Point3d.new(10, 10, 10) array = [1, 1, 1] # This will return a Length distance = array.distance(point)
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)] array = [10, 10, 10] # This will return a Length distance = array.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)] array = [10, 10, 10] # This will return a Length distance = array.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) array = [1, 0, 0] # This will return a Float, in this case 22.0 dot_product = array.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:
array = [1, 2, 3] # This will return a new Vector3d normal_vector = array.normalize
The normalize! method is used to normalize a vector in place (setting its length to 1).
Returns:
array = [1, 2, 3] # This will modify 'array' in place array.normalize!
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:
array = [10, 10, 10] vector = Geom::Vector3d.new(0, 0, 1) # This will return a new Array point = array.offset(vector)
The offset! method is used to offset a point by a vector. The array is modified in place.
Arguments:
Returns:
array = [10, 10, 10] vector = Geom::Vector3d.new(0, 0, 1) # This will modify 'array' in place array.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)] array = [10, 10, 10] # This will return a true or false value on_plane = array.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)] array = [10, 10, 10] # This will return a true or false value on_plane = array.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)] array = [10, 10, 10] # This will return a new Array point_on_line = array.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)] array = [10, 10, 10] # This will return a new Array point_on_plane = array.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:
point1 = Geom::Point3d.new(10, 20, 30) transform = Geom::Transformation.new(point1) array = [1, 2, 3] # This will return a new Array point2 = array.transform(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:
point = Geom::Point3d.new(10, 20, 30) transform = Geom::Transformation.new(point) array = [1, 2, 3] # This will modify 'array' in place array.transform!(transform)
The vector_to method is used to create an array as a vector from one point to a second point.
Arguments:
Returns:
point = Geom::Point3d.new(10, 20, 30) array = [1, 2, 3] # This will return a new Vector3d vector = array.vector_to(point)
The x method retrieves the x coordinate.
Returns:
array = [1, 2, 3] # This will return a Fixnum, in this case 1 x = array.x array = [1.0, 2.0, 3.0] # This will return a Float, in this case 1.0 x = array.x
The x= method sets the x coordinate.
Arguments:
Returns:
array = [1, 2, 3] # This will initialize the x value as a Float array.x = 2.5 # This will initialize the x value as a Fixnum array.x = 5
The y method retrieves the y coordinate.
Returns:
array = [1, 2, 3] # This will return a Fixnum, in this case 2 y = array.y array = [1.0, 2.0, 3.0] # This will return a Float, in this case 2.0 y = array.y
The y= method sets the y coordinate.
Arguments:
Returns:
array = [1, 2, 3] # This will initialize the y value as a Float array.y = 2.5 # This will initialize the y value as a Fixnum array.y = 5
The z method retrieves the z coordinate.
Returns:
array = [1, 2, 3] # This will return a Fixnum, in this case 3 z = array.z array = [1.0, 2.0, 3.0] # This will return a Float, in this case 3.0 z = array.z
The z= method sets the z coordinate.
Arguments:
Returns:
array = [1, 2, 3] # This will initialize the z value as a Float array.z = 2.5 # This will initialize the z value as a Fixnum array.z = 5