Vec3

Associated namespace: sm.vec3

A userdata object representing a 3D vector.

Values:

Functions:

Operations:

OperationDescription
Vec3 + Vec3Returns the sum of two vectors.
Vec3 / Vec3Returns the quotient of two vectors, dividing element by element.
Vec3 / numberReturns the quotient of a vector and a scalar.
Vec3 == Vec3Checks if two vectors are equal.
Vec3 < Vec3Returns whether the first vector is "less than" the second.
Vec3 * Vec3Returns the product of two vectors, multiplying element by element.
Vec3 * numberReturns the product of a vector and a scalar.
Vec3 - Vec3Returns the difference of two vectors.
tostring(Vec3)String representation of vector.
-Vec3Returns 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:

TypeNameDescription
Vec3v1The first vector.
Vec3v2The second vector.

Returns:

TypeDescription
Vec3The cross product.

dot(v1, v2)

Returns the dot product of a vector.

Parameters:

TypeNameDescription
Vec3v1The first vector.
Vec3v2The second vector.

Returns:

TypeDescription
numberThe 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:

TypeNameDescription
Vec3vectorThe vector.

Returns:

TypeDescription
numberThe length of the vector.

length2(vector)

Returns the squared length of the vector.

Parameters:

TypeNameDescription
Vec3vectorThe vector.

Returns:

TypeDescription
numberThe squared length of the vector.

max(v1, v2)

Returns the maximum value between two vectors components.

Parameters:

TypeNameDescription
Vec3v1The first vector.
Vec3v2The second vector.

Returns:

TypeDescription
Vec3Component wise maximum value vector.

min(v1, v2)

Returns the minimum value between two vectors components.

Parameters:

TypeNameDescription
Vec3v1The first vector.
Vec3v2The second vector.

Returns:

TypeDescription
Vec3Component wise minimum value vector.

normalize(vector)

Normalizes a vector, ie. converts to a unit vector of length 1.

Parameters:

TypeNameDescription
Vec3vectorThe vector.

Returns:

TypeDescription
Vec3The normalized vector.

rotate(vector, angle, normal)

Rotate a vector around an axis.

Parameters:

TypeNameDescription
Vec3vectorThe vector.
numberangleThe angle.
Vec3normalThe axis to be rotated around.

Returns:

TypeDescription
Vec3The rotated vector.

rotateX(vector, angle)

Rotate a vector around the X axis.

Parameters:

TypeNameDescription
Vec3vectorThe vector.
numberangleThe angle.

Returns:

TypeDescription
Vec3The rotated vector.

rotateY(vector, angle)

Rotate a vector around the Y axis.

Parameters:

TypeNameDescription
Vec3vectorThe vector.
numberangleThe angle.

Returns:

TypeDescription
Vec3The rotated vector.

rotateZ(vector, angle)

Rotate a vector around the Z axis.

Parameters:

TypeNameDescription
Vec3vectorThe vector.
numberangleThe angle.

Returns:

TypeDescription
Vec3The rotated vector.

safeNormalize(vector, fallback)

Normalizes a vector with safety, ie. converts to a unit vector of length 1.

Parameters:

TypeNameDescription
Vec3vectorThe vector.
Vec3fallbackThe fallback vector

Returns:

TypeDescription
Vec3The normalized vector.