Vec3
A userdata object representing a 3D vector.
Values:
-
Get: Returns the X value of a vector.Set: Sets the X value of a vector.
-
Get: Returns the Y value of a vector.Set: Sets the Y value of a vector.
-
Get: Returns the Z value of a vector.Set: Sets the Z value of a vector.
Operations:
| Operation | Returns | Description |
|---|---|---|
Vec3 + Vec3 |
Vec3 | Returns the sum of two vectors. |
Vec3 + number |
Vec3 | Returns the per element sum of a vector and a scalar. |
Vec3 / Vec3 |
Vec3 | Returns the quotient of two vectors, dividing element by element. |
Vec3 / number |
Vec3 | Returns the quotient of a vector and a scalar. |
Vec3 == Vec3 |
boolean | Checks if two vectors are equal. |
Vec3 < Vec3 |
boolean | Returns whether the first vector is "less than" the second. |
Vec3 * Vec3 |
Vec3 | Returns the product of two vectors, multiplying element by element. |
Vec3 * number |
Vec3 | Returns the product of a vector and a scalar. |
Vec3 - Vec3 |
Vec3 | Returns the difference of two vectors. |
Vec3 - number |
Vec3 | Returns the per element difference of a vector and a scalar. |
tostring(Vec3) |
string | String representation of vector. |
-Vec3 |
Vec3 | Returns the negated vector. |
Functions
abs
vec3:abs( )
Returns a vector of only positive values by taking the absolute value of each component in the input vector.
Parameters:
| Name | Type | Description |
|---|---|---|
v |
Vec3 | The vector. |
Returns:
| Type | Description |
|---|---|
| Vec3 | The absolute value vector. |
ceil
vec3:ceil( )
Ceil each component of the vector
Parameters:
| Name | Type | Description |
|---|---|---|
vector |
Vec3 | The vector. |
Returns:
| Type | Description |
|---|---|
| Vec3 | The ceiled vector. |
cross
vec3:cross( v2 )
Returns the cross product of two vectors.
Parameters:
Returns:
| Type | Description |
|---|---|
| Vec3 | The cross product. |
dot
vec3:dot( v2 )
Returns the dot product of a vector.
Parameters:
Returns:
| Type | Description |
|---|---|
| number | The dot product. |
floor
vec3:floor( )
Floor each component of the vector
Parameters:
| Name | Type | Description |
|---|---|---|
vector |
Vec3 | The vector. |
Returns:
| Type | Description |
|---|---|
| Vec3 | The floored vector. |
length
vec3:length( )
Returns the length of the vector.
If you want the squared length, using length2 is faster than squaring the result of this function.
Parameters:
| Name | Type | Description |
|---|---|---|
vector |
Vec3 | The vector. |
Returns:
| Type | Description |
|---|---|
| number | The length of the vector. |
length2
vec3:length2( )
Returns the squared length of the vector.
Parameters:
| Name | Type | Description |
|---|---|---|
vector |
Vec3 | The vector. |
Returns:
| Type | Description |
|---|---|
| number | The squared length of the vector. |
max
vec3:max( v2 )
Returns the maximum value between two vectors components.
Parameters:
Returns:
| Type | Description |
|---|---|
| Vec3 | Component wise maximum value vector. |
min
vec3:min( v2 )
Returns the minimum value between two vectors components.
Parameters:
Returns:
| Type | Description |
|---|---|
| Vec3 | Component wise minimum value vector. |
normalize
vec3:normalize( )
Normalizes a vector, ie. converts to a unit vector of length 1.
Parameters:
| Name | Type | Description |
|---|---|---|
vector |
Vec3 | The vector. |
Returns:
| Type | Description |
|---|---|
| Vec3 | The normalized vector. |
rotate
vec3:rotate( angle, normal )
Rotate a vector around an axis.
Parameters:
| Name | Type | Description |
|---|---|---|
vector |
Vec3 | The vector. |
angle |
number | The angle. |
normal |
Vec3 | The axis to be rotated around. |
Returns:
| Type | Description |
|---|---|
| Vec3 | The rotated vector. |
rotateX
vec3:rotateX( angle )
Rotate a vector around the X axis.
Parameters:
| Name | Type | Description |
|---|---|---|
vector |
Vec3 | The vector. |
angle |
number | The angle. |
Returns:
| Type | Description |
|---|---|
| Vec3 | The rotated vector. |
rotateY
vec3:rotateY( angle )
Rotate a vector around the Y axis.
Parameters:
| Name | Type | Description |
|---|---|---|
vector |
Vec3 | The vector. |
angle |
number | The angle. |
Returns:
| Type | Description |
|---|---|
| Vec3 | The rotated vector. |
rotateZ
vec3:rotateZ( angle )
Rotate a vector around the Z axis.
Parameters:
| Name | Type | Description |
|---|---|---|
vector |
Vec3 | The vector. |
angle |
number | The angle. |
Returns:
| Type | Description |
|---|---|
| Vec3 | The rotated vector. |
safeNormalize
vec3:safeNormalize( fallback )
Normalizes a vector with safety, ie. converts to a unit vector of length 1.
Parameters:
Returns:
| Type | Description |
|---|---|
| Vec3 | The normalized vector. |