Extensions Vector
scripts/vscripts/alyxlib/extensions/vector.lua
Methods
Perpendicular
Calculates the perpendicular vector to the current vector.
Returns
- Vector
The perpendicular vector.
IsParallelTo
Checks if the current vector is parallel to the given vector.
Parameters
vector
Vector
The vector to compare with.
Returns
- boolean
True if the vectors are parallel, false otherwise.
Slerp
Spherical linear interpolation between the calling vector and the target vector over t = [0, 1].
Parameters
target
Vector
The target vector to interpolate towards.t
number
The interpolation factor, ranging from 0 to 1.
Returns
- Vector
The resulting vector after spherical linear interpolation.
LocalTranslate
Translates a vector within a local coordinate system. This function computes a new vector by applying an offset relative to the local axes defined by the forward, right, and up direction vectors.
- `offset.x`: Translation along the forward vector.
- `offset.y`: Translation along the right vector.
- `offset.z`: Translation along the up vector.
Parameters
offset
Vector
The translation offset vector. This defines how much to move along the forward, right, and up directions.forward
Vector
The forward direction of the local coordinate system.right
Vector
The right direction of the local coordinate system.up
Vector
The up direction of the local coordinate system.
Returns
- Vector
A new vector representing the translated position.
AngleDiff
Calculates the angle difference in degrees between the calling vector and the given vector. This is always the smallest angle.
Parameters
vector
Vector
The vector to calculate the angle difference with.
Returns
- number
Angle difference in degrees.
SignedAngleDiff
Calculates the signed angle difference between the calling vector and the given vector around the specified axis.
Parameters
vector
Vector
The vector to calculate the angle difference with.axis(optional)
Vector
The axis of rotation around which the angle difference is calculated.
Returns
- number
The signed angle difference in degrees.
Unpack
Unpacks the x, y, z components as 3 return values.
Returns
number
x component
number
y component
number
z component
LengthSquared
Returns the squared length (magnitude) of the vector.
More efficient than calculating the actual length as it avoids using sqrt().
Returns
- number
IsSimilarTo
Checks if this vector is similar to another vector within a given tolerance.
Parameters
vector
Vector
The vector to compare against.tolerance(optional)
number
The tolerance within which the vectors are considered similar. Default is 1e-5. See math.isclose
Returns
- boolean
Returns true if the vectors are similar within the tolerance, otherwise false.
Clone
Creates a copy of the vector.
Returns
- Vector
A new vector with the same components as the original.