Vec3
Associated namespace: sm.vec3
A userdata object representing a 3D vector.
Values:
Functions:
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) | String representation of vector. |
-Vec3 | Returns the negated vector. |
x number
Get:
Returns the X value of a vector.
Set:
Sets the X value of a vector.
y number
Get:
Returns the Y value of a vector.
Set:
Sets the Y value of a vector.
z number
Get:
Returns the Z value of a vector.
Set:
Sets the Z value of a vector.
cross(v1, v2)
Returns the cross product of two vectors.
Parameters:
Type | Name | Description |
Vec3 | v1 | The first vector. |
Vec3 | v2 | The second vector. |
Returns:
Type | Description |
Vec3 | The cross product. |
dot(v1, v2)
Returns the dot product of a vector.
Parameters:
Type | Name | Description |
Vec3 | v1 | The first vector. |
Vec3 | v2 | The second vector. |
Returns:
Type | Description |
number | The dot product. |
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.
Parameters:
Type | Name | Description |
Vec3 | vector | The vector. |
Returns:
Type | Description |
number | The length of the vector. |
length2(vector)
Returns the squared length of the vector.
Parameters:
Type | Name | Description |
Vec3 | vector | The vector. |
Returns:
Type | Description |
number | The squared length of the vector. |
max(v1, v2)
Returns the maximum value between two vectors components.
Parameters:
Type | Name | Description |
Vec3 | v1 | The first vector. |
Vec3 | v2 | The second vector. |
Returns:
Type | Description |
Vec3 | Component wise maximum value vector. |
min(v1, v2)
Returns the minimum value between two vectors components.
Parameters:
Type | Name | Description |
Vec3 | v1 | The first vector. |
Vec3 | v2 | The second vector. |
Returns:
Type | Description |
Vec3 | Component wise minimum value vector. |
normalize(vector)
Normalizes a vector, ie. converts to a unit vector of length 1.
Parameters:
Type | Name | Description |
Vec3 | vector | The vector. |
Returns:
Type | Description |
Vec3 | The normalized vector. |
rotate(vector, angle, normal)
Rotate a vector around an axis.
Parameters:
Type | Name | Description |
Vec3 | vector | The vector. |
number | angle | The angle. |
Vec3 | normal | The axis to be rotated around. |
Returns:
Type | Description |
Vec3 | The rotated vector. |
rotateX(vector, angle)
Rotate a vector around the X axis.
Parameters:
Type | Name | Description |
Vec3 | vector | The vector. |
number | angle | The angle. |
Returns:
Type | Description |
Vec3 | The rotated vector. |
rotateY(vector, angle)
Rotate a vector around the Y axis.
Parameters:
Type | Name | Description |
Vec3 | vector | The vector. |
number | angle | The angle. |
Returns:
Type | Description |
Vec3 | The rotated vector. |
rotateZ(vector, angle)
Rotate a vector around the Z axis.
Parameters:
Type | Name | Description |
Vec3 | vector | The vector. |
number | angle | The angle. |
Returns:
Type | Description |
Vec3 | The rotated vector. |
safeNormalize(vector, fallback)
Normalizes a vector with safety, ie. converts to a unit vector of length 1.
Parameters:
Type | Name | Description |
Vec3 | vector | The vector. |
Vec3 | fallback | The fallback vector |
Returns:
Type | Description |
Vec3 | The normalized vector. |