Editors' picksPINE LIBRARY

Vector3

Updated
Library "Vector3"
Representation of 3D vectors and points.
This structure is used to pass 3D positions and directions around. It also contains functions for doing common vector operations.
Besides the functions listed below, other classes can be used to manipulate vectors and points as well.
For example the Quaternion and the Matrix4x4 classes are useful for rotating or transforming vectors and points.
___
**Reference:**
- github.com/phoboslab/q1k3/blob/master/source/math_utils.js
- github.com/lauripiispanen/vectorz/blob/master/3d.js
- github.com/thormeier/vanilla-vectors-3d/blob/master/src/Vector.js
- movable-type.co.uk/scripts/geodesy/docs/vector3d.js.html
- docs.unity3d.com/ScriptReference/Vector3.html
- referencesource.microsoft.com/
- github.com/Unity-Technologies/UnityCsReference/blob/master/Runtime/Export/Math/Vector3.cs
\

new(x, y, z)
  Create a new `Vector3`.
  Parameters:
    x (float): `float` Property `x` value, (optional, default=na).
    y (float): `float` Property `y` value, (optional, default=na).
    z (float): `float` Property `z` value, (optional, default=na).
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.new(1.1, 1, 1)
```

from(value)
  Create a new `Vector3` from a single value.
  Parameters:
    value (float): `float` Properties positional value, (optional, default=na).
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.from(1.1)
```

from_Array(values, fill_na)
  Create a new `Vector3` from a list of values, only reads up to the third item.
  Parameters:
    values (float[]): `array<float>` Vector property values.
    fill_na (float): `float` Parameter value to replace missing indexes, (optional, defualt=na).
  Returns: `Vector3` Generated new vector.
___
**Notes:**
- Supports any size of array, fills non available fields with `na`.
___
**Usage:**
```
.from_Array(array.from(1.1, fill_na=33))
.from_Array(array.from(1.1, 2, 3))
```

from_Vector2(values)
  Create a new `Vector3` from a `Vector2`.
  Parameters:
    values (Vector2 type from RicardoSantos/CommonTypesMath/1): `Vector2` Vector property values.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.from:Vector2(.Vector2.new(1, 2.0))
```
___
**Notes:**
- Type `Vector2` from CommonTypesMath library.

from_Quaternion(values)
  Create a new `Vector3` from a `Quaternion`'s `x, y, z` properties.
  Parameters:
    values (Quaternion type from RicardoSantos/CommonTypesMath/1): `Quaternion` Vector property values.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.from_Quaternion(.Quaternion.new(1, 2, 3, 4))
```
___
**Notes:**
- Type `Quaternion` from CommonTypesMath library.

from_String(expression, separator, fill_na)
  Create a new `Vector3` from a list of values in a formated string.
  Parameters:
    expression (string): `array<float>` String with the list of vector properties.
    separator (string): `string` Separator between entries, (optional, default=`","`).
    fill_na (float): `float` Parameter value to replace missing indexes, (optional, defualt=na).
  Returns: `Vector3` Generated new vector.
___
**Notes:**
- Supports any size of array, fills non available fields with `na`.
- `",,"` Empty fields will be ignored.
___
**Usage:**
```
.from_String("1.1", fill_na=33))
.from_String("(1.1,, 3)") // 1.1 , 3.0, NaN // empty field will be ignored!!
```

back()
  Create a new `Vector3` object in the form `(0, 0, -1)`.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.back()
```

front()
  Create a new `Vector3` object in the form `(0, 0, 1)`.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.front()
```

up()
  Create a new `Vector3` object in the form `(0, 1, 0)`.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.up()
```

down()
  Create a new `Vector3` object in the form `(0, -1, 0)`.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.down()
```

left()
  Create a new `Vector3` object in the form `(-1, 0, 0)`.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.left()
```

right()
  Create a new `Vector3` object in the form `(1, 0, 0)`.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.right()
```

zero()
  Create a new `Vector3` object in the form `(0, 0, 0)`.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.zero()
```

one()
  Create a new `Vector3` object in the form `(1, 1, 1)`.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.one()
```

minus_one()
  Create a new `Vector3` object in the form `(-1, -1, -1)`.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.minus_one()
```

unit_x()
  Create a new `Vector3` object in the form `(1, 0, 0)`.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.unit_x()
```

unit_y()
  Create a new `Vector3` object in the form `(0, 1, 0)`.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.unit_y()
```

unit_z()
  Create a new `Vector3` object in the form `(0, 0, 1)`.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.unit_z()
```

nan()
  Create a new `Vector3` object in the form `(na, na, na)`.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.nan()
```

random(max, min)
  Generate a vector with random properties.
  Parameters:
    max (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Maximum defined range of the vector properties.
    min (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Minimum defined range of the vector properties.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.random(.from(math.pi), .from(-math.pi))
```

random(max)
  Generate a vector with random properties (min set to 0.0).
  Parameters:
    max (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Maximum defined range of the vector properties.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.random(.from(math.pi))
```

method copy(this)
  Copy a existing `Vector3`
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .one().copy()
```

method i_add(this, other)
  Modify a instance of a vector by adding a vector to it.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    other (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Other Vector.
  Returns: `Vector3` Updated source vector.
___
**Usage:**
```
a = .from(1) , a.i_add(.up())
```

method i_add(this, value)
  Modify a instance of a vector by adding a vector to it.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    value (float): `float` Value.
  Returns: `Vector3` Updated source vector.
___
**Usage:**
```
a = .from(1) , a.i_add(3.2)
```

method i_subtract(this, other)
  Modify a instance of a vector by subtracting a vector to it.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    other (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Other Vector.
  Returns: `Vector3` Updated source vector.
___
**Usage:**
```
a = .from(1) , a.i_subtract(.down())
```

method i_subtract(this, value)
  Modify a instance of a vector by subtracting a vector to it.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    value (float): `float` Value.
  Returns: `Vector3` Updated source vector.
___
**Usage:**
```
a = .from(1) , a.i_subtract(3)
```

method i_multiply(this, other)
  Modify a instance of a vector by multiplying a vector with it.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    other (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Other Vector.
  Returns: `Vector3` Updated source vector.
___
**Usage:**
```
a = .from(1) , a.i_multiply(.left())
```

method i_multiply(this, value)
  Modify a instance of a vector by multiplying a vector with it.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    value (float): `float` value.
  Returns: `Vector3` Updated source vector.
___
**Usage:**
```
a = .from(1) , a.i_multiply(3)
```

method i_divide(this, other)
  Modify a instance of a vector by dividing it by another vector.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    other (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Other Vector.
  Returns: `Vector3` Updated source vector.
___
**Usage:**
```
a = .from(1) , a.i_divide(.forward())
```

method i_divide(this, value)
  Modify a instance of a vector by dividing it by another vector.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    value (float): `float` Value.
  Returns: `Vector3` Updated source vector.
___
**Usage:**
```
a = .from(1) , a.i_divide(3)
```

method i_mod(this, other)
  Modify a instance of a vector by modulo assignment with another vector.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    other (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Other Vector.
  Returns: `Vector3` Updated source vector.
___
**Usage:**
```
a = .from(1) , a.i_mod(.back())
```

method i_mod(this, value)
  Modify a instance of a vector by modulo assignment with another vector.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    value (float): `float` Value.
  Returns: `Vector3` Updated source vector.
___
**Usage:**
```
a = .from(1) , a.i_mod(3)
```

method i_pow(this, exponent)
  Modify a instance of a vector by modulo assignment with another vector.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    exponent (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Exponent Vector.
  Returns: `Vector3` Updated source vector.
___
**Usage:**
```
a = .from(1) , a.i_pow(.up())
```

method i_pow(this, exponent)
  Modify a instance of a vector by modulo assignment with another vector.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    exponent (float): `float` Exponent Value.
  Returns: `Vector3` Updated source vector.
___
**Usage:**
```
a = .from(1) , a.i_pow(2)
```

method length_squared(this)
  Squared length of the vector.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1)
  Returns: `float` The squared length of this vector.
___
**Usage:**
```
a = .one().length_squared()
```

method magnitude_squared(this)
  Squared magnitude of the vector.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
  Returns: `float` The length squared of this vector.
___
**Usage:**
```
a = .one().magnitude_squared()
```

method length(this)
  Length of the vector.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
  Returns: `float` The length of this vector.
___
**Usage:**
```
a = .one().length()
```

method magnitude(this)
  Magnitude of the vector.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
  Returns: `float` The Length of this vector.
___
**Usage:**
```
a = .one().magnitude()
```

method normalize(this, magnitude, eps)
  Normalize a vector with a magnitude of 1(optional).
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    magnitude (float): `float` Value to manipulate the magnitude of normalization, (optional, default=1.0).
    eps (float)
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .new(33, 50, 100).normalize() // (x=0.283, y=0.429, z=0.858)
a = .new(33, 50, 100).normalize(2) // (x=0.142, y=0.214, z=0.429)
```

method to_String(this, precision)
  Converts source vector to a string format, in the form `"(x, y, z)"`.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    precision (string): `string` Precision format to apply to values (optional, default='').
  Returns: `string` Formated string in a `"(x, y, z)"` format.
___
**Usage:**
```
a = .one().to_String("#.###")
```

method to_Array(this)
  Converts source vector to a array format.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
  Returns: `array<float>` List of the vector properties.
___
**Usage:**
```
a = .new(1, 2, 3).to_Array()
```

method to_Vector2(this)
  Converts source vector to a Vector2 in the form `x, y`.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
  Returns: `Vector2` Generated new vector.
___
**Usage:**
```
a = .from(1).to_Vector2()
```

method to_Quaternion(this, w)
  Converts source vector to a Quaternion in the form `x, y, z, w`.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Sorce vector.
    w (float): `float` Property of `w` new value.
  Returns: `Quaternion` Generated new vector.
___
**Usage:**
```
a = .from(1).to_Quaternion(w=1)
```

method add(this, other)
  Add a vector to source vector.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    other (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Other vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).add(.unit_z())
```

method add(this, value)
  Add a value to each property of the vector.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    value (float): `float` Value.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).add(2.0)
```

add(value, other)
  Add each property of a vector to a base value as a new vector.
  Parameters:
    value (float): `float` Value.
    other (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(2) , b = .add(1.0, a)
```

method subtract(this, other)
  Subtract vector from source vector.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    other (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Other vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).subtract(.left())
```

method subtract(this, value)
  Subtract a value from each property in source vector.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    value (float): `float` Value.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).subtract(2.0)
```

subtract(value, other)
  Subtract each property in a vector from a base value and create a new vector.
  Parameters:
    value (float): `float` Value.
    other (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .subtract(1.0, .right())
```

method multiply(this, other)
  Multiply a vector by another.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    other (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Other vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).multiply(.up())
```

method multiply(this, value)
  Multiply each element in source vector with a value.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    value (float): `float` Value.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).multiply(2.0)
```

multiply(value, other)
  Multiply a value with each property in a vector and create a new vector.
  Parameters:
    value (float): `float` Value.
    other (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .multiply(1.0, .new(1, 2, 1))
```

method divide(this, other)
  Divide a vector by another.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    other (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Other vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).divide(.from(2))
```

method divide(this, value)
  Divide each property in a vector by a value.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    value (float): `float` Value.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).divide(2.0)
```

divide(value, other)
  Divide a base value by each property in a vector and create a new vector.
  Parameters:
    value (float): `float` Value.
    other (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .divide(1.0, .from(2))
```

method mod(this, other)
  Modulo a vector by another.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    other (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Other vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).mod(.from(2))
```

method mod(this, value)
  Modulo each property in a vector by a value.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    value (float): `float` Value.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).mod(2.0)
```

mod(value, other)
  Modulo a base value by each property in a vector and create a new vector.
  Parameters:
    value (float): `float` Value.
    other (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .mod(1.0, .from(2))
```

method negate(this)
  Negate a vector in the form `(zero - this)`.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .one().negate()
```

method pow(this, other)
  Modulo a vector by another.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    other (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Other vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(2).pow(.from(3))
```

method pow(this, exponent)
  Raise the vector elements by a exponent.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    exponent (float): `float` The exponent to raise the vector by.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).pow(2.0)
```

pow(value, exponent)
  Raise value into a vector raised by the elements in exponent vector.
  Parameters:
    value (float): `float` Base value.
    exponent (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` The exponent to raise the vector of base value by.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .pow(1.0, .from(2))
```

method sqrt(this)
  Square root of the elements in a vector.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).sqrt()
```

method abs(this)
  Absolute properties of the vector.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).abs()
```

method max(this)
  Highest property of the vector.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
  Returns: `float` Highest value amongst the vector properties.
___
**Usage:**
```
a = .new(1, 2, 3).max()
```

method min(this)
  Lowest element of the vector.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
  Returns: `float` Lowest values amongst the vector properties.
___
**Usage:**
```
a = .new(1, 2, 3).min()
```

method floor(this)
  Floor of vector a.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .new(1.33, 1.66, 1.99).floor()
```

method ceil(this)
  Ceil of vector a.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .new(1.33, 1.66, 1.99).ceil()
```

method round(this)
  Round of vector elements.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .new(1.33, 1.66, 1.99).round()
```

method round(this, precision)
  Round of vector elements to n digits.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    precision (int): `int` Number of digits to round the vector elements.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .new(1.33, 1.66, 1.99).round(1) // 1.3, 1.7, 2
```

method fractional(this)
  Fractional parts of vector.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1.337).fractional() // 0.337
```

method dot_product(this, other)
  Dot product of two vectors.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    other (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Other vector.
  Returns: `float` Dot product.
___
**Usage:**
```
a = .from(2).dot_product(.left())
```

method cross_product(this, other)
  Cross product of two vectors.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    other (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Other vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).cross_produc(.right())
```

method scale(this, scalar)
  Scale vector by a scalar value.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    scalar (float): `float` Value to scale the the vector by.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).scale(2)
```

method rescale(this, magnitude)
  Rescale a vector to a new magnitude.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    magnitude (float): `float` Value to manipulate the magnitude of normalization.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(20).rescale(1)
```

method equals(this, other)
  Compares two vectors.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    other (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Other vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).equals(.one())
```

method sin(this)
  Sine of vector.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).sin()
```

method cos(this)
  Cosine of vector.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).cos()
```

method tan(this)
  Tangent of vector.
  Namespace types: TMath.Vector3
  Parameters:
    this (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).tan()
```

vmax(a, b)
  Highest elements of the properties from two vectors.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Vector.
    b (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .vmax(.one(), .from(2))
```

vmax(a, b, c)
  Highest elements of the properties from three vectors.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Vector.
    b (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Vector.
    c (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .vmax(.new(0.1, 2.5, 3.4), .from(2), .from(3))
```

vmin(a, b)
  Lowest elements of the properties from two vectors.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Vector.
    b (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .vmin(.one(), .from(2))
```

vmin(a, b, c)
  Lowest elements of the properties from three vectors.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Vector.
    b (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Vector.
    c (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .vmin(.one(), .from(2), .new(3.3, 2.2, 0.5))
```

distance(a, b)
  Distance between vector `a` and `b`.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    b (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Target vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = distance(.from(3), .unit_z())
```

clamp(a, min, max)
  Restrict a vector between a min and max vector.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    min (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Minimum boundary vector.
    max (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Maximum boundary vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .clamp(a=.new(2.9, 1.5, 3.9), min=.from(2), max=.new(2.5, 3.0, 3.5))
```

clamp_magnitude(a, radius)
  Vector with its magnitude clamped to a radius.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.object, vector with properties that should be restricted to a radius.
    radius (float): `float` Maximum radius to restrict magnitude of vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .clamp_magnitude(.from(21), 7)
```

lerp_unclamped(a, b, rate)
  `Unclamped` linearly interpolates between provided vectors by a rate.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    b (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Target vector.
    rate (float): `float` Rate of interpolation, range(0 > 1) where 0 == source vector and 1 == target vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .lerp_unclamped(.from(1), .from(2), 1.2)
```

lerp(a, b, rate)
  Linearly interpolates between provided vectors by a rate.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    b (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Target vector.
    rate (float): `float` Rate of interpolation, range(0 > 1) where 0 == source vector and 1 == target vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = lerp(.one(), .from(2), 0.2)
```

herp(start, start_tangent, end, end_tangent, rate)
  Hermite curve interpolation between provided vectors.
  Parameters:
    start (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Start vector.
    start_tangent (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Start vector tangent.
    end (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` End vector.
    end_tangent (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` End vector tangent.
    rate (int): `float` Rate of the movement from `start` to `end` to get position, should be range(0 > 1).
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
s = .new(0, 0, 0) , st = .new(0, 1, 1)
e = .new(1, 2, 2) , et = .new(-1, -1, 3)
h = .herp(s, st, e, et, 0.3)
```
___
**Reference:** en.m.wikibooks.org/wiki/Cg_Programming/Unity/Hermite_Curves

herp_2(a, b, rate)
  Hermite curve interpolation between provided vectors.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    b (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Target vector.
    rate (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Rate of the movement per component from `start` to `end` to get position, should be range(0 > 1).
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
h = .herp_2(.one(), .new(0.1, 3, 2), 0.6)
```

noise(a)
  3D Noise based on Morgan McGuire @morgan3d
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = noise(.one())
```
___
**Reference:**
- thebookofshaders.com/11/
- shadertoy.com/view/4dS3Wd

rotate(a, axis, angle)
  Rotate a vector around a axis.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    axis (string): `string` The plane to rotate around, `option="x", "y", "z"`.
    angle (float): `float` Angle in radians.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .rotate(.from(3), 'y', math.toradians(45.0))
```

rotate_x(a, angle)
  Rotate a vector on a fixed `x`.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    angle (float): `float` Angle in radians.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .rotate_x(.from(3), math.toradians(90.0))
```

rotate_y(a, angle)
  Rotate a vector on a fixed `y`.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    angle (float): `float` Angle in radians.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .rotate_y(.from(3), math.toradians(90.0))
```

rotate_yaw_pitch(a, yaw, pitch)
  Rotate a vector by yaw and pitch values.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    yaw (float): `float` Angle in radians.
    pitch (float): `float` Angle in radians.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .rotate_yaw_pitch(.from(3), math.toradians(90.0), math.toradians(45.0))
```

project(a, normal, eps)
  Project a vector off a plane defined by a normal.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    normal (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` The normal of the surface being reflected off.
    eps (float): `float` Minimum resolution to void division by zero (default=0.000001).
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .project(.one(), .down())
```

project_on_plane(a, normal, eps)
  Projects a vector onto a plane defined by a normal orthogonal to the plane.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    normal (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` The normal of the surface being reflected off.
    eps (float): `float` Minimum resolution to void division by zero (default=0.000001).
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .project_on_plane(.one(), .left())
```

project_to_2d(a, camera_position, camera_target)
  Project a vector onto a two dimensions plane.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    camera_position (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Camera position.
    camera_target (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Camera target plane position.
  Returns: `Vector2` Generated new vector.
___
**Usage:**
```
a = .project_to_2d(.one(), .new(2, 2, 3), .zero())
```

reflect(a, normal)
  Reflects a vector off a plane defined by a normal.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    normal (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` The normal of the surface being reflected off.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .reflect(.one(), .right())
```

angle(a, b, eps)
  Angle in degrees between two vectors.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    b (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Target vector.
    eps (float): `float` Minimum resolution to void division by zero (default=1.0e-15).
  Returns: `float` Angle value in degrees.
___
**Usage:**
```
a = .angle(.one(), .up())
```

angle_signed(a, b, axis)
  Signed angle in degrees between two vectors.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    b (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Target vector.
    axis (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Axis vector.
  Returns: `float` Angle value in degrees.
___
**Usage:**
```
a = .angle_signed(.one(), .left(), .down())
```
___
**Notes:**
- The smaller of the two possible angles between the two vectors is returned, therefore the result will never
be greater than 180 degrees or smaller than -180 degrees.
- If you imagine the from and to vectors as lines on a piece of paper, both originating from the same point,
then the /axis/ vector would point up out of the paper.
- The measured angle between the two vectors would be positive in a clockwise direction and negative in an
anti-clockwise direction.
___
**Reference:**
- github.com/Unity-Technologies/UnityCsReference/blob/master/Runtime/Export/Math/Vector3.cs

angle2d(a, b)
  2D angle between two vectors.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    b (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Target vector.
  Returns: `float` Angle value in degrees.
___
**Usage:**
```
a = .angle2d(.one(), .left())
```

transform_Matrix(a, M)
  Transforms a vector by the given matrix.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    M (matrix<float>): `matrix<float>` A 4x4 matrix. The transformation matrix.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
mat = matrix.new<float>(4, 0)
mat.add_row(0, array.from(0.0, 0.0, 0.0, 1.0))
mat.add_row(1, array.from(0.0, 0.0, 1.0, 0.0))
mat.add_row(2, array.from(0.0, 1.0, 0.0, 0.0))
mat.add_row(3, array.from(1.0, 0.0, 0.0, 0.0))
b = .transform_Matrix(.one(), mat)
```

transform_M44(a, M)
  Transforms a vector by the given matrix.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    M (M44 type from RicardoSantos/CommonTypesMath/1): `M44` A 4x4 matrix. The transformation matrix.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .transform_M44(.one(), .M44.new(0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0))
```
___
**Notes:**
- Type `M44` from `CommonTypesMath` library.

transform_normal_Matrix(a, M)
  Transforms a vector by the given matrix.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    M (matrix<float>): `matrix<float>` A 4x4 matrix. The transformation matrix.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
mat = matrix.new<float>(4, 0)
mat.add_row(0, array.from(0.0, 0.0, 0.0, 1.0))
mat.add_row(1, array.from(0.0, 0.0, 1.0, 0.0))
mat.add_row(2, array.from(0.0, 1.0, 0.0, 0.0))
mat.add_row(3, array.from(1.0, 0.0, 0.0, 0.0))
b = .transform_normal_Matrix(.one(), mat)
```

transform_normal_M44(a, M)
  Transforms a vector by the given matrix.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    M (M44 type from RicardoSantos/CommonTypesMath/1): `M44` A 4x4 matrix. The transformation matrix.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .transform_normal_M44(.one(), .M44.new(0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0))
```
___
**Notes:**
- Type `M44` from `CommonTypesMath` library.

transform_Array(a, rotation)
  Transforms a vector by the given Quaternion rotation value.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector. The source vector to be rotated.
    rotation (float[]): `array<float>` A 4 element array. Quaternion. The rotation to apply.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .transform_Array(.one(), array.from(0.2, 0.2, 0.2, 1.0))
```
___
**Reference:**
- referencesource.microsoft.com/

transform_Quaternion(a, rotation)
  Transforms a vector by the given Quaternion rotation value.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector. The source vector to be rotated.
    rotation (Quaternion type from RicardoSantos/CommonTypesMath/1): `array<float>` A 4 element array. Quaternion. The rotation to apply.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .transform_Quaternion(.one(), .Quaternion.new(0.2, 0.2, 0.2, 1.0))
```
___
**Notes:**
- Type `Quaternion` from `CommonTypesMath` library.
___
**Reference:**
- referencesource.microsoft.com/
Release Notes
v2 added rotate_z() and minor update for consistency.

Added:
rotate_z(a, angle)
  Rotate a vector on a fixed `z`.
  Parameters:
    a (Vector3 type from RicardoSantos/CommonTypesMath/1): `Vector3` Source vector.
    angle (float): `float` Angle in radians.
  Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .rotate_z(.from(3), math.toradians(90.0))
```
3darraysfunctionlibraryMarket GeometryMATHvector3

Pine library

In true TradingView spirit, the author has published this Pine code as an open-source library so that other Pine programmers from our community can reuse it. Cheers to the author! You may use this library privately or in other open-source publications, but reuse of this code in a publication is governed by House rules.

Disclaimer