Vec3 Class
3-dimensional vector
Constructor
Vec3
-
x
-
y
-
z
Parameters:
-
x
Number -
y
Number -
z
Number
Example:
var v = new Vec3(1, 2, 3);
console.log('x=' + v.x); // x=1
Item Index
Methods
Methods
almostEquals
-
v
-
precision
Check if a vector equals is almost equal to another one.
Parameters:
-
v
Vec3 -
precision
Number
Returns:
bool
almostZero
-
precision
Check if a vector is almost zero
Parameters:
-
precision
Number
copy
-
source
Copies value of source to this vector.
Parameters:
-
source
Vec3
Returns:
this
crossmat
()
Mat3
Get the cross product matrix a_cross from a vector, such that a x b = a_cross * b = c
Returns:
distanceTo
-
p
Get distance from this point to another point
Parameters:
-
p
Vec3
Returns:
isAntiparallelTo
-
v
-
precision
Check if the vector is anti-parallel to another vector.
Parameters:
-
v
Vec3 -
precision
NumberSet to zero for exact comparisons
Returns:
isZero
()
Returns:
bool
lerp
-
v
-
t
-
target
Do a linear interpolation between two vectors
mult
-
scalar
-
target
Multiply the vector with a scalar
Parameters:
-
scalar
Number -
target
Vec3
Returns:
negate
-
target
Make the vector point in the opposite direction.
Parameters:
-
target
Vec3Optional target to save in
Returns:
norm
()
Number
Get the 2-norm (length) of the vector
Returns:
norm2
()
Number
Get the squared length of the vector
Returns:
normalize
()
Number
Normalize the vector. Note that this changes the values in the vector.
Returns:
Returns the norm of the vector
scale
-
scalar
-
target
Multiply the vector with a scalar.
Parameters:
-
scalar
Number -
target
Vec3
Returns:
set
-
x
-
y
-
z
Set the vectors' 3 elements
Parameters:
-
x
Number -
y
Number -
z
Number
Returns:
Vec3
setZero
()
Set all components of the vector to zero.
tangents
-
t1
-
t2
Compute two artificial tangents to the vector
toArray
()
Converts to an array
Returns:
Array
toString
()
Converts to a more readable format
Returns:
string