Vector3d Class
The vector3d class contains functions and operators for dealing with 3-dimensional math.
Contents
Operators
Operators for adding (+), subtracting (-), and scaling (* or /) are supported. You may also get the magnitude (length) of a vector with the # operator.
set
vector3d:set(number x, number y[, number z])
Change the x, y, and z axis for a vector. You may also manually change these values separately.
length
number vector3d:length()
Returns the length (aka magnitude) of a vector. This is the same as the # operator.
normal
vector3d vector3d:normal()
Returns a normalized (vector with a magnitude of 1) copy of a vector.
dot
number vector3d:dot(vector3d other)
Returns the dot product of a vector against some other vector.
cross
vector3d vector3d:cross(vector3d other)
Returns the cross product of a vector against some other vector.
rotateAboutX
vector3d vector3d:rotateAboutX(number angle)
Returns a copy of the vector rotated around the X axis by some angle in radians (not degrees!).
rotateAboutY
vector3d vector3d:rotateAboutY(number angle)
Returns a copy of the vector rotated around the Y axis by some angle in radians (not degrees!).
rotateAboutZ
vector3d vector3d:rotateAboutZ(number angle)
Returns a copy of the vector rotated around the Z axis by some angle in radians (not degrees!).
rotateAbout
vector3d vector3d:rotateAbout(vector3d axis, number angle)
Returns a copy of the vector rotated around a user-specified axis by some angle in radians (not degrees!).
lerp
vector3d vector3d:lerp(vector3d target, number ratio)
Linearly interpolate (lerp) a vector to rotate it towards the target vector by 'ratio' amount. 'ratio' should be between 0 (no rotation) and 1 (full rotation). Linear interpolation is quicker to calculate but less accurate than spherical linear interpolation (slerp).
slerp
vector3d vector3d:slerp(vector3d target, number ratio)
Spherical linearl interpolate (lerp) a vector to rotate it towards the target vector by 'ratio' amount. 'ratio' should be between 0 (no rotation) and 1 (full rotation). Spherical linear interpolation is slower to calculate but is visually smoother than linear interpolation (lerp).
moveTowards
vector3d vector3d:moveTowards(vector3d target, number dist)
Move this vector up to 'dist' distance towards the target vector. This will automatically prevent overstepping the target should 'dist' be longer than the actual distance to target. If distance is negative, this function will move away from the target vector.