Module vec3

A 3 component vector.

Functions

new (x, y, z) The public constructor.
clone (a) Clone a vector.
add (a, b) Add two vectors.
sub (a, b) Subtract one vector from another.
mul (a, b) Multiply a vector by another vector.
div (a, b) Divide a vector by another.
normalize (a) Scale a vector to unit length (1).
normalize_len (a) Scale a vector to unit length (1), and return the input length.
trim (a, len) Trim a vector to a given length
cross (a, b) Get the cross product of two vectors.
dot (a, b) Get the dot product of two vectors.
len (a) Get the length of a vector.
len2 (a) Get the squared length of a vector.
dist (a, b) Get the distance between two vectors.
dist2 (a, b) Get the squared distance between two vectors.
scale (a, b) Scale a vector by a scalar.
rotate (a, phi, axis) Rotate vector about an axis.
perpendicular (a) Get the perpendicular vector of a vector.
lerp (a, b, s) Lerp between two vectors.
unpack (a) Unpack a vector into individual components.
component_min (a, b) Return the component-wise minimum of two vectors.
component_max (a, b) Return the component-wise maximum of two vectors.
is_vec3 (a) Return a boolean showing if a table is or is not a vec3.
is_zero (a) Return a boolean showing if a table is or is not a zero vec3.
has_nan (a) Return whether any component is NaN
to_string (a) Return a formatted string.

Tables

vec3 Constants


Functions

new (x, y, z)
The public constructor.

Parameters:

  • x Can be of three types:
    number X component table {x, y, z} or {x=x, y=y, z=z} scalar To fill the vector eg. {x, x, x}
  • y number Y component
  • z number Z component

Returns:

    vec3 out
clone (a)
Clone a vector.

Parameters:

  • a vec3 Vector to be cloned

Returns:

    vec3 out
add (a, b)
Add two vectors.

Parameters:

  • a vec3 Left hand operand
  • b vec3 Right hand operand

Returns:

    vec3 out
sub (a, b)
Subtract one vector from another. Order: If a and b are positions, computes the direction and distance from b to a.

Parameters:

  • a vec3 Left hand operand
  • b vec3 Right hand operand

Returns:

    vec3 out
mul (a, b)
Multiply a vector by another vector. Component-wise multiplication not matrix multiplication.

Parameters:

  • a vec3 Left hand operand
  • b vec3 Right hand operand

Returns:

    vec3 out
div (a, b)
Divide a vector by another. Component-wise inv multiplication. Like a non-uniform scale().

Parameters:

  • a vec3 Left hand operand
  • b vec3 Right hand operand

Returns:

    vec3 out
normalize (a)
Scale a vector to unit length (1).

Parameters:

  • a vec3 vector to normalize

Returns:

    vec3 out
normalize_len (a)
Scale a vector to unit length (1), and return the input length.

Parameters:

  • a vec3 vector to normalize

Returns:

  1. vec3 out
  2. number input vector length
trim (a, len)
Trim a vector to a given length

Parameters:

  • a vec3 vector to be trimmed
  • len number Length to trim the vector to

Returns:

    vec3 out
cross (a, b)
Get the cross product of two vectors. Resulting direction is right-hand rule normal of plane defined by a and b. Magnitude is the area spanned by the parallelograms that a and b span. Order: Direction determined by right-hand rule.

Parameters:

  • a vec3 Left hand operand
  • b vec3 Right hand operand

Returns:

    vec3 out
dot (a, b)
Get the dot product of two vectors.

Parameters:

  • a vec3 Left hand operand
  • b vec3 Right hand operand

Returns:

    number dot
len (a)
Get the length of a vector.

Parameters:

  • a vec3 Vector to get the length of

Returns:

    number len
len2 (a)
Get the squared length of a vector.

Parameters:

  • a vec3 Vector to get the squared length of

Returns:

    number len
dist (a, b)
Get the distance between two vectors.

Parameters:

  • a vec3 Left hand operand
  • b vec3 Right hand operand

Returns:

    number dist
dist2 (a, b)
Get the squared distance between two vectors.

Parameters:

  • a vec3 Left hand operand
  • b vec3 Right hand operand

Returns:

    number dist
scale (a, b)
Scale a vector by a scalar.

Parameters:

  • a vec3 Left hand operand
  • b number Right hand operand

Returns:

    vec3 out
rotate (a, phi, axis)
Rotate vector about an axis.

Parameters:

  • a vec3 Vector to rotate
  • phi number Angle to rotate vector by (in radians)
  • axis vec3 Axis to rotate by

Returns:

    vec3 out
perpendicular (a)
Get the perpendicular vector of a vector.

Parameters:

  • a vec3 Vector to get perpendicular axes from

Returns:

    vec3 out
lerp (a, b, s)
Lerp between two vectors.

Parameters:

  • a vec3 Left hand operand
  • b vec3 Right hand operand
  • s number Step value

Returns:

    vec3 out
unpack (a)
Unpack a vector into individual components.

Parameters:

  • a vec3 Vector to unpack

Returns:

  1. number x
  2. number y
  3. number z
component_min (a, b)
Return the component-wise minimum of two vectors.

Parameters:

  • a vec3 Left hand operand
  • b vec3 Right hand operand

Returns:

    vec3 A vector where each component is the lesser value for that component between the two given vectors.
component_max (a, b)
Return the component-wise maximum of two vectors.

Parameters:

  • a vec3 Left hand operand
  • b vec3 Right hand operand

Returns:

    vec3 A vector where each component is the lesser value for that component between the two given vectors.
is_vec3 (a)
Return a boolean showing if a table is or is not a vec3.

Parameters:

  • a vec3 Vector to be tested

Returns:

    boolean is_vec3
is_zero (a)
Return a boolean showing if a table is or is not a zero vec3.

Parameters:

  • a vec3 Vector to be tested

Returns:

    boolean is_zero
has_nan (a)
Return whether any component is NaN

Parameters:

  • a vec3 Vector to be tested

Returns:

    boolean if x,y, or z are nan
to_string (a)
Return a formatted string.

Parameters:

  • a vec3 Vector to be turned into a string

Returns:

    string formatted

Tables

vec3
Constants

Fields:

  • unit_x X axis of rotation
  • unit_y Y axis of rotation
  • unit_z Z axis of rotation
  • zero Empty vector
generated by LDoc 1.4.6 Last updated 2022-05-07 22:53:35