Module vec4
vec4: A simple 3-component vector
Functions
vec4 (x, y, z, w) | Create a new vector with components x, y, z: (Can also be used to duplicate a vector: vec4(v)) |
copy (v) | Create a copy of a vector: |
fromvec3 (v, w) | Create a copy of a vec2 vector: |
fromvec2 (v, z, w) | Create a copy of a vec3 vector: |
vec4:set (x, y, z, w) | Set the components of a vector: |
vec4:add (v) | Add a vector (or number) to self (in-place) |
addnew (a, b) | Add two vectors (or numbers) to create a new vector |
vec4:sub (v) | Subtract a vector (or number) to self (in-place) |
subnew (a, b) | Subtract two vectors (or numbers) to create a new vector |
vec4:mul (v) | Multiply a vector (or number) to self (in-place) |
mulnew (a, b) | Multiply two vectors (or numbers) to create a new vector |
vec4:div (v) | Divide a vector (or number) to self (in-place) |
divnew (a, b) | Divide two vectors (or numbers) to create a new vector |
vec4:pow (v) | Raise to power a vector (or number) to self (in-place) |
pownew (a, b) | Raise to power two vectors (or numbers) to create a new vector |
vec4:mod (v) | Calculate modulo a vector (or number) to self (in-place) |
modnew (a, b) | Calculate modulo two vectors (or numbers) to create a new vector |
vec4:min (v) | Calculate minimum of elements (in-place) |
minnew (a, b) | Calculate minimum of elements to create a new vector |
vec4:max (v) | Calculate maximum of elements (in-place) |
maxnew (a, b) | Calculate maximum of elements to create a new vector |
vec4:clip (lo, hi) | Constrain vector to range (in-place) |
vec4:clip (lo, hi) | Constrain vector to range to create a new vector |
vec4:relativewrap (dimx, dimy, dimz, dimw) | Determine shortest relative vector in a toroidal space |
vec4:relativewrapnew (dimx, dimy, dimz, dimw) | Create new vector as shortest relative vector in a toroidal space |
vec4:lerp (v, f) | interpolate from self to v by factor of f |
lerpnew (a, b, f) | create a vector from the linear interpolation of two vectors: |
vec4:normalize () | set the length of the vector to 1 (unit vector) (randomized direction if self length was zero) |
vec4:normalizenew () | return a normalized copy of the vector (randomized direction if self length was zero) |
vec4:limit (maximum) | Impose a maximum magnitude Rescales vector if greater than maximum |
vec4:limitnew (maximum) | Create a copy of a vector, limited to a maximum magnitude Rescales vector if greater than maximum |
vec4:setmag (m) | Rescale a vector to a specific magnitude: |
vec4:setmagnew (m) | Return a vector copy rescaled to a specific magnitude: |
vec4:length () | return the length of a vector (Can also use #vector) |
dot (a, b) | return the dot product of two vectors: |
vec4:distance (p) | The distance between two vectors (two points) (The relative distance from self to p) |
anglebetween (a, b) | The angle between two vectors (two points) (The relative angle from self to v) |
Functions
- vec4 (x, y, z, w)
-
Create a new vector with components x, y, z:
(Can also be used to duplicate a vector: vec4(v))
Parameters:
- x number or vector (optional, default 0)
- y number (optional, default 0)
- z number (optional, default 0)
- w number (optional, default 0)
- copy (v)
-
Create a copy of a vector:
Parameters:
- v vector to copy
- fromvec3 (v, w)
-
Create a copy of a vec2 vector:
Parameters:
- v vec3
- w number (optional, default 1)
- fromvec2 (v, z, w)
-
Create a copy of a vec3 vector:
Parameters:
- v vec3
- z number (optional, default 0)
- w number (optional, default 1)
- vec4:set (x, y, z, w)
-
Set the components of a vector:
Parameters:
- x component (optional, default 0)
- y component (optional, default 0)
- z component (optional, default 0)
- w component (optional, default 0)
Returns:
-
self
- vec4:add (v)
-
Add a vector (or number) to self (in-place)
Parameters:
- v number or vector to add
Returns:
-
self
- addnew (a, b)
-
Add two vectors (or numbers) to create a new vector
Parameters:
- a vector or number
- b vector or number
Returns:
-
new vector
- vec4:sub (v)
-
Subtract a vector (or number) to self (in-place)
Parameters:
- v number or vector to sub
Returns:
-
self
- subnew (a, b)
-
Subtract two vectors (or numbers) to create a new vector
Parameters:
- a vector or number
- b vector or number
Returns:
-
new vector
- vec4:mul (v)
-
Multiply a vector (or number) to self (in-place)
Parameters:
- v number or vector to mul
Returns:
-
self
- mulnew (a, b)
-
Multiply two vectors (or numbers) to create a new vector
Parameters:
- a vector or number
- b vector or number
Returns:
-
new vector
- vec4:div (v)
-
Divide a vector (or number) to self (in-place)
Parameters:
- v number or vector to div
Returns:
-
self
- divnew (a, b)
-
Divide two vectors (or numbers) to create a new vector
Parameters:
- a vector or number
- b vector or number
Returns:
-
new vector
- vec4:pow (v)
-
Raise to power a vector (or number) to self (in-place)
Parameters:
- v number or vector to pow
Returns:
-
self
- pownew (a, b)
-
Raise to power two vectors (or numbers) to create a new vector
Parameters:
- a vector or number
- b vector or number
Returns:
-
new vector
- vec4:mod (v)
-
Calculate modulo a vector (or number) to self (in-place)
Parameters:
- v number or vector to mod
Returns:
-
self
- modnew (a, b)
-
Calculate modulo two vectors (or numbers) to create a new vector
Parameters:
- a vector or number
- b vector or number
Returns:
-
new vector
- vec4:min (v)
-
Calculate minimum of elements (in-place)
Parameters:
- v number or vector limit
Returns:
-
self
- minnew (a, b)
-
Calculate minimum of elements to create a new vector
Parameters:
- a vector or number
- b vector or number
Returns:
-
new vector
- vec4:max (v)
-
Calculate maximum of elements (in-place)
Parameters:
- v number or vector limit
Returns:
-
self
- maxnew (a, b)
-
Calculate maximum of elements to create a new vector
Parameters:
- a vector or number
- b vector or number
Returns:
-
new vector
- vec4:clip (lo, hi)
-
Constrain vector to range (in-place)
Parameters:
- lo vector or number minimum value
- hi vector or number minimum value
Returns:
-
self
- vec4:clip (lo, hi)
-
Constrain vector to range to create a new vector
Parameters:
- lo vector or number minimum value
- hi vector or number minimum value
Returns:
-
new vector
- vec4:relativewrap (dimx, dimy, dimz, dimw)
-
Determine shortest relative vector in a toroidal space
Parameters:
- dimx width of space (optional, default 1)
- dimy height of space (optional, default dimx)
- dimz depth of space (optional, default dimx)
- dimw fourth dimension of space (optional, default dimx)
Returns:
-
self
- vec4:relativewrapnew (dimx, dimy, dimz, dimw)
-
Create new vector as shortest relative vector in a toroidal space
Parameters:
- dimx width of space (optional, default 1)
- dimy height of space (optional, default dimx)
- dimz depth of space (optional, default dimx)
- dimw fourth dimension of space (optional, default dimx)
Returns:
-
new vector
- vec4:lerp (v, f)
-
interpolate from self to v by factor of f
Parameters:
- v vector
- f interpolation factor from self to v (0 = none, 1 = full)
Returns:
-
self
- lerpnew (a, b, f)
-
create a vector from the linear interpolation of two vectors:
Parameters:
- a vector
- b vector
- f interpolation factor from a to b (0 = none, 1 = full)
Returns:
-
new vector
- vec4:normalize ()
-
set the length of the vector to 1 (unit vector)
(randomized direction if self length was zero)
Returns:
-
self
- vec4:normalizenew ()
-
return a normalized copy of the vector
(randomized direction if self length was zero)
Returns:
-
vector of length 1 (unit vector)
- vec4:limit (maximum)
-
Impose a maximum magnitude
Rescales vector if greater than maximum
Parameters:
- maximum maximum magnitude of vector
Returns:
-
self
- vec4:limitnew (maximum)
-
Create a copy of a vector, limited to a maximum magnitude
Rescales vector if greater than maximum
Parameters:
- maximum maximum magnitude of vector
Returns:
-
new vector
- vec4:setmag (m)
-
Rescale a vector to a specific magnitude:
Parameters:
- m new magnitude
Returns:
-
self
- vec4:setmagnew (m)
-
Return a vector copy rescaled to a specific magnitude:
Parameters:
- m new magnitude
Returns:
-
new vector
- vec4:length ()
-
return the length of a vector
(Can also use #vector)
Returns:
-
length
- dot (a, b)
-
return the dot product of two vectors:
Parameters:
- a vector
- b vector
Returns:
-
dot product
- vec4:distance (p)
-
The distance between two vectors (two points)
(The relative distance from self to p)
Parameters:
- p target to measure distance to
Returns:
-
distance
- anglebetween (a, b)
-
The angle between two vectors (two points)
(The relative angle from self to v)
Parameters:
- a vector to measure angle between
- b vector to measure angle between
Returns:
-
distance