Class: Vector
Class representing a vector in 3D space.
Vectors are the building blocks of 3D geometry. A Vector represents a point or direction in 3D space with x, y, and z coordinates. You'll use vectors everywhere - to define positions, directions, distances, and transformations.
When to use Vector
- Positioning objects - specify where geometry lives in 3D space
- Defining directions - set rotation axes, extrusion directions, normals
- Mathematical operations - add, subtract, cross product, dot product, normalize
- Measuring - calculate distances, angles between directions
Quick start
Key methods at a glance
| Method | What it does |
|---|---|
x(), y(), z() | Get individual coordinates |
length() | Distance from origin |
distance(v) | Distance between two vectors |
add(v), sub(v) | Vector arithmetic |
cross(v), dot(v) | Cross and dot products |
normalized() | Unit vector (length = 1) |
multiply(scale) | Scale the vector |
getAngle(v) | Angle between vectors (radians) |
rotated(angle) | Rotate around an axis |
translate(v) | Move by a vector |
copy() | Create an independent copy |
Method: constructor
Constructs a new Vector object.
Parameters
vector(Point): The vector to initialize the object with. Defaults to [0, 0, 0].
Example
Method: vector
Gets the vector.
Returns
The vector.
Example
Method: vector
Sets the vector for this object.
Parameters
vector: The vector to set.
Example
Method: type
Gets the type of the vector.
Returns
The type of the vector.
Example
Method: x
Gets the x coordinate of the vector.
Returns
The x coordinate of the vector.
Example
Method: y
Gets the y coordinate of the vector.
Returns
The y coordinate of the vector.
Example
Method: z
Gets the z coordinate of the vector.
Returns
The z coordinate of the vector.
Example
Method: length
Returns the length of the vector.
Returns
The length of the vector.
Example
Method: toTuple
Converts the vector to a tuple representation.
Returns
The tuple representation of the vector as [x, y, z].
Example
Static Method: by2Point
Creates a new Vector by subtracting the coordinates of the end Vector from the coordinates of the start Vector.
Parameters
start(IVector): The start Vector.end(IVector): The end Vector.
Returns
A new Vector representing the difference between the end and start Vectors.
Example
Method: cross
Calculates the cross product of this vector and the given vector.
Parameters
v(IVector): The vector to calculate the cross product with.
Returns
The resulting vector from the cross product operation.
Example
Method: dot
Calculates the dot product between this vector and the given vector.
Parameters
v(IVector): The vector to calculate the dot product with.
Returns
The dot product of the two vectors.
Example
Method: sub
Subtracts the given vector from this vector.
Parameters
v(IVector): The vector to subtract.
Returns
A new vector representing the subtraction result.
Example
Method: add
Adds a vector to the current vector.
Parameters
v(IVector): The vector to be added.
Returns
A new vector that is the result of the addition.
Example
Method: multiply
Multiplies the vector by the given scale.
Parameters
scale(number): The scale factor to multiply the vector by.
Returns
A new Vector object representing the result of the multiplication.
Example
Method: normalized
Returns a new Vector object that represents the normalized version of this vector.
Returns
A new Vector object representing the normalized vector.
Example
Method: normalize
Normalizes the vector.
Returns
The normalized vector.
Example
Method: getCenter
Returns the center vector.
Returns
The center vector.
Example
Method: getAngle
Calculates the angle between two vectors.
Parameters
v(IVector): The vector to calculate the angle with.
Returns
The angle between the two vectors in radians.
Example
Method: copy
Creates a copy of the vector.
Returns
A new instance of the Vector class with the same values as the original vector.
Example
Method: projectToPlane
Projects the vector onto a plane.
Parameters
plane(IPlane): The plane onto which the vector will be projected.
Returns
The projected vector.
Example
Method: equals
Checks if this vector is equal to the given vector.
Parameters
other(IVector): The vector to compare with.
Returns
True if the vectors are equal, false otherwise.
Example
Method: toPnt
Converts the vector to a point in 3D space.
Returns
The converted point.
Example
Method: toDir
Converts the vector to a direction.
Returns
The direction representation of the vector.
Example
Method: toVec
Converts the vector to a Vector object.
Returns
The converted Vector object.
Example
Method: reversed
Reverses the vector.
Returns
The reversed vector.
Example
Method: distance
Calculates the distance between two vectors.
Parameters
second(IVector): The second vector to calculate the distance to.
Returns
The distance between the two vectors.
Example
Method: reverse
Reverses the vector in place.
Returns
The reversed vector.
Example
Method: rotated
Rotates the vector by the specified angle around the given center and direction.
Parameters
angle(number): The angle (in radians) by which to rotate the vector.center(Point = [0): The center point around which to rotate the vector. Defaults to [0, 0, 0].
Returns
A new Vector object representing the rotated vector.
Example
Method: translate
Translates the current vector by adding the given vector.
Parameters
vector(IVector): The vector to be added.
Returns
A new vector representing the result of the translation.
Example
Method: rotate
Rotates the vector by the specified angle around the given center and direction.
Parameters
angle(number): The angle (in radians) by which to rotate the vector.center(Point = [0): The center point around which to rotate the vector. Defaults to [0, 0, 0].
Returns
The rotated vector.
Example
Method: setPlane
Sets the plane of the vector.
Parameters
localPlane(IPlane): The local plane.
Returns
A new Vector object with the transformed vector.
Example
Method: mirrorByCurve
Mirrors the vector by a given curve.
Parameters
curve(ICurve): The curve to mirror the vector by.
Returns
The mirrored vector.
Example
Method: delete
Deletes the vector.
Example
Method: dump
Returns a string representation of the vector.
Returns
The string representation of the vector.