Vec3
Associated namespace: sm.vec3
A userdata object representing a 3D vector.
Operations:Operation | Description |
---|---|
Vec3 + Vec3 | Returns the sum of two vectors. |
Vec3 / Vec3 | Returns the quotient of two vectors, dividing element by element. |
Vec3 / number | Returns the quotient of a vector and a scalar. |
Vec3 == Vec3 | Checks if two vectors are equal. |
Vec3 < Vec3 | Returns whether the first vector is "less than" the second. |
Vec3 * Vec3 | Returns the product of two vectors, multiplying element by element. |
Vec3 * number | Returns the product of a vector and a scalar. |
Vec3 - Vec3 | Returns the difference of two vectors. |
tostring( Vec3 ) | Returns the string representation of a vector. |
-Vec3 | Returns the negated vector. |
-
x
[ number ]Get
: The vector's X value.Set
: Sets the vector's X value.
-
y
[ number ]Get
: The vector's Y value.Set
: Sets the vector's Y value.
-
z
[ number ]Get
: The vector's Z value.Set
: Sets the vector's Z value.
Functions
cross
vec3:cross( vector )
Returns the cross product of two vectors.
Arguments:Returns:
- [ Vec3 ]: The cross product.
dot
vec3:dot( vector )
Returns the dot product of two vectors.
Arguments:Returns:
- [ Vec3 ]: The dot product.
length
vec3:length( vector )
Returns the length of the vector.
If you want the squared length, using length2 is faster than squaring the result of this function.
Arguments:vec3
[ Vec3 ]: The vector.
- [ number ]: The length.
length2
vec3:length2( vector )
Returns the squared length of the vector.
Arguments:vec3
[ Vec3 ]: The vector.
- [ number ]: The squared length.
max
vec3:max( vector )
Returns the maximum value between two vectors components.
Arguments:Returns:
- [ Vec3 ]: Component wise maximum value vector.
min
vec3:min( vector )
Returns the minimum value between two vectors components.
Arguments:Returns:
- [ Vec3 ]: Component wise minimum value vector.
normalize
vec3:normalize()
Normalizes the vector, ie. converts it to a unit vector of length 1.
Arguments:vec3
[ Vec3 ]: The vector.
- [ Vec3 ]: The normalized vector.
rotate
vec3:rotate( angle, normal )
Rotates the vector around an axis.
The angle value uses radians.
Arguments:vec3
[ Vec3 ]: The vector.angle
[ number ]: The angle.normal
[ Vec3 ]: The axis to be rotated around.
- [ Vec3 ]: The rotated vector.
rotateX
vec3:rotateX( angle )
Rotates the vector around the X axis.
The angle value uses radians.
Arguments:vec3
[ Vec3 ]: The vector.angle
[ number ]: The angle.
- [ Vec3 ]: The rotated vector.
rotateY
vec3:rotateY( angle )
Rotates the vector around the Y axis.
The angle value uses radians.
Arguments:vec3
[ Vec3 ]: The vector.angle
[ number ]: The angle.
- [ Vec3 ]: The rotated vector.
rotateZ
vec3:rotateZ( angle )
Rotates the vector around the Z axis.
The angle value uses radians.
Arguments:vec3
[ Vec3 ]: The vector.angle
[ number ]: The angle.
- [ Vec3 ]: The rotated vector.
safeNormalize
vec3:safeNormalize( fallback )
Normalizes a vector with safety, ie. converts to a unit vector of length 1.
Arguments:Returns:
- [ Vec3 ]: The normalized vector.