const Vec3 = require('tera-vec3')
let v = new Vec3(1, 2, 3)
console.log(v) // prints '1,2,3'
v.add({x: 3})
console.log(v) // prints '4,2,3'
const Vec3 = require('tera-vec3')
let v1 = new Vec3(1, 2, 3)
let v2 = v1.addN(1, 1, 1)
console.log(v1) // prints '1,2,3'
console.log(v2) // prints '2,3,4'
Creates a new instance of Vec3. vector
may be one of the following (all coordinates are optional):
- x, y, z
- [x, y, z]
- {x, y, z}
undefined
coordinates are replaced with 0
, all other types are coerced using Number()
.
Note: This function does not throw errors, and NaN
is considered a valid value for coordinates.
Adds a vector to this.
Subtracts a vector from this.
Multiplies coordinates by vector
. undefined
coordinates default to 1
.
Divides coordinates by vector
. undefined
coordinates default to 1
.
Multiplies all coordinates by scalar
.
Rotates this vector around its Z axis by radians
.
Normalizes this vector, setting its length()
to 1
.
Sets all coordinates to their absolute values.
Rounds all coordinates to the nearest integer.
Returns the length of this vector.
Returns the squared length of this vector. (micro-optimization)
Returns the distance between two vectors, ignoring Z axis.
Returns the squared distance between two vectors, ignoring Z axis. (micro-optimization)
Returns the distance between two vectors.
Returns the squared distance between two vectors. (micro-optimization)
Returns the 2D arc tangent from this vector to the specified one, ignoring Z axis.
Returns a boolean indicating whether one or more coordinates are not a number.
Returns a copy of this Vec3.
Returns a boolean indicating whether compared coordinates are the same.
Returns a string representation of this Vec3.