The Vector3d class is used to represent vectors in a 3 dimensional space.
Vectors in SketchUp have a direction and a length, but not a starting point.
There are numerous tutorials on 3D vectors available on the internet.
The % method is used to compute the dot product between two vectors. This is an alias of the dot method.
Arguments:
Returns:
vector = Geom::Vector3d.new 0,0,1 vector2 = Geom::Vector3d.new 0,1,0 d = vector.dot vector2
The * method is used to compute the cross product between two vectors.
The cross product, also called the vector product, is an operation on two
vectors. The cross product of two vectors produces a third vector which is
perpendicular to the plane in which the first two lie.
This is an alias of the cross method.
Arguments:
Returns:
vector = Geom::Vector3d.new 1,0,0 vector2 = Geom::Vector3d.new 0,1,0
The - method is used to add a vector to this one.
Arguments:
Returns:
vector = Geom::Vector3d.new 0,0,2 vector2 = Geom::Vector3d.new 0,1,0 new_vector = vector + vector2
The - method is used to subtract a vector from this one.
Arguments:
Returns:
vector = Geom::Vector3d.new 0,0,2 vector2 = Geom::Vector3d.new 0,1,0 new_vector = vector - vector2
The < method is used to determine if a vector is less than another.
Arguments:
Returns:
vector = Geom::Vector3d.new 0,0,2 vector2 = Geom::Vector3d.new 0,1,0 lt = vector < vector2
The == method is used to determine if two vectors are equal to within tolerance.
Arguments:
Returns:
vector = Geom::Vector3d.new 1,0,0 vector2 = Geom::Vector3d.new 0,1,0 status = vector == vector2 # Returns false UI.messagebox status
The [] method is used to access the coordinates of a vector as if it was an
Array. The index must be 0, 1 or 2.
The following are equivalent:
Arguments:
Returns:
vector = Geom::Vector3d.new 1,0,0 value = vector[0] if (value) UI.messagebox value else UI.messagebox "Failure" end
The []= method is used to set the coordinates of a vector as if it was an Array. The value of i must be 0, 1 or 2.
Arguments:
Returns:
value = vector[i] = coordinate
The angle_between method is used to compute the angle (in radians) between this vector and another vector.
Arguments:
Returns:
angle = vector.angle_between vector2
The axes method is used to compute an arbitrary set of axes with the given
vector as the z-axis direction.
Returns an Array of three vectors [xaxis, yaxis, zaxis]
Returns:
vector = Geom::Vector3d.new 1,0,0 a = vector.axes
The clone method is used to make a copy of a vector.
This method is equivalent to vec2 = Geom::Vector3d.new(vec)
Returns:
vector = Geom::Vector3d.new 1,0,0 vector2 = vector.clone
The cross method is used to compute the cross product between two vectors.
The cross product, also called the vector product, is an operation on two
vectors. The cross product of two vectors produces a third vector which is
perpendicular to the plane in which the first two lie.
Arguments:
Returns:
vector = Geom::Vector3d.new 1,0,0 vector2 = Geom::Vector3d.new 0,1,0 v = vector.cross vector2
The dot method is used to compute the dot product between two vectors.
Arguments:
Returns:
vector = Geom::Vector3d.new 0,0,1 vector2 = Geom::Vector3d.new 0,1,0 d = vector.dot vector2
The inspect method is used to inspect the contents of a vector as a friendly string.
Returns:
vector = vector.inspect
The length method is used to retrieve the length of the vector.
Returns:
vector = Geom::Vector3d.new 0,0,1 l = vector.length
The length= method is used to set the length of the vector. The length must be greater than 0.
Arguments:
Returns:
vector = Geom::Vector3d.new 0,0,1 l = vector.length UI.messagebox l newl = vector.length = 2
The linear_combination method is used to create a new vector as a linear
combination of other vectors. This method is generally used to get a vector
at some percentage between two vectors.
A linear combination is a standard term for vector math. It is defined as
point = weight1 * point1 + weight2 * point2.
In addition to the 4-argument form detailed here, you may also call this
method with 6 parameters in the form of:
Arguments:
Returns:
# Create a vector that is a 50%/50% linear combination of two others. vec1 = Geom::Vector3d.new 3,0,0 vec2 = Geom::Vector3d.new 0,3,0 new_vector = Geom::Vector3d.linear_combination(0.5, vec1, 0.5, vec2) # new_vector will now contain a Vector3d(1.5, 1.5, 0)
The new method is used to create a new vector. Typically you call this by passing an x, y, and z value, but you may also call it in any of the following forms:
Arguments:
Returns:
# A vector that runs up the Z axis. vector = Geom::Vector3d.new 0,0,1 if (vector) UI.messagebox vector else UI.messagebox "Failure" end
The normalize method is used to return a vector that is a unit vector of another.
Returns:
vector = Geom::Vector3d.new 0,0,1 vector2 = vector.normalize
The normalize! method is used to convert a vector into a unit vector,
in place.
Another way to do this is vec.length = 1
Returns:
vector = Geom::Vector3d.new 0,0,1 vector.normalize!
The parallel method is used to determine if this vector is parallel to another vector to within tolerance.
Arguments:
Returns:
status = vector.parallel? vector2
The perpendicular? method is used to determine if this vector is perpendicular to another vector to within tolerance.
Arguments:
Returns:
vector = Geom::Vector3d.new 0,0,1 vector2 = Geom::Vector3d.new 0,1,0 status = vector.perpendicular? vector2
The reverse method is used to return a new vector that is the reverse of this vector, while leaving the original unchanged.
Returns:
vector2 = vector.reverse
The reverse! method is used to reverse the vector in place.
Returns:
vector.reverse!
The samedirection? method is used to determine if this vector is parallel to and in the same direction as another vector to within tolerance.
Arguments:
Returns:
vector = Geom::Vector3d.new 0,0,1 vector2 = Geom::Vector3d.new 0,1,0 status = vector.sime_direction? vector2
The set! method is used to set the coordinates of the vector.
This is a shortcut for writing:
You may also call this method with an array or another vector:
Arguments:
Returns:
vector = Geom::Vector3d.new 0,0,1 vector2 = vector.set! 1,0,0
The to_a method retrieves the coordinates of the vector in an Array [x, y, z].
Returns:
a = vector.to_a
The to_s method is used to format the vector as a String.
Returns:
vector = Geom::Vector3d.new 0,0,1 string = vector.to_s
Apply a Transformation to a vector, returning a new vector. The original vector is unchanged by this method.
Arguments:
Returns:
vector2 = vector.transform! transformation
Apply a Transformation to a vector. The vector itself is modified.
Arguments:
Returns:
vector.transform! transformation
The unitvector? method is used to see if the vector is a unit vector.
This is equivalent to vec.length == 1.0
Returns:
vector = Geom::Vector3d.new 0,0,1 status = vector.unitvector
The valid? method is used to verify if a vector is valid. A vector is valid if its length is not zero.
Returns:
status = vector.valid
The x method is used to retrieve the x coordinate of the vector.
Returns:
x = vector.x
The x= method is used to set the x coordinate of the vector.
Arguments:
Returns:
vector = Geom::Vector3d.new 1,2,3 x = vector.x = 10
The y method is used to retrieve the y coordinate of the vector.
Returns:
vector = Geom::Vector3d.new 1,2,3 y = vector.y
Set the y coordinate of the vector.
Arguments:
Returns:
vector = Geom::Vector3d.new 1,2,3 y = vector.y = 10
Get the z coordinate of the vector.
Returns:
vector = Geom::Vector3d.new 1,2,3 z = vector.z
Set the z coordinate of the vector.
Arguments:
Returns:
vector = Geom::Vector3d.new 1,2,3 z = vector.z = 10