new Vector(
x?,y?,z?):Vector
Creates a vector from coordinates.
If all coordinates are omitted, the vector is created with coordinates (0, 0, 1). If z is omitted while x or y is provided, z defaults to 0.
number
X coordinate of 3D vector.
number
Y coordinate of 3D vector.
number
Z coordinate of 3D vector.
Vector
new Vector(
start,end):Vector
Creates a vector from start to end.
Start point.
End point.
Vector
get x():
number
X coordinate of the vector.
number
set x(
x):void
Sets the X coordinate of the vector.
number
X coordinate.
void
get y():
number
Y coordinate of the vector.
number
set y(
y):void
Sets the Y coordinate of the vector.
number
Y coordinate.
void
get z():
number
Z coordinate of the vector.
number
set z(
z):void
Sets the Z coordinate of the vector.
number
Z coordinate.
void
add(
other):this
Adds the coordinates of other to this vector.
Vector
Other vector.
this
added(
other):Vector
Returns a new vector resulting from adding other to this vector.
Vector
Other vector.
Vector
angle(
other):number
Returns the angle between this vector and other.
Vector
Other vector.
number
clone():
Vector
Creates a new vector with the same coordinates as this vector.
Vector
copy(
other):this
Copies the coordinates of other to this vector.
Vector
Vector to copy.
this
cross(
other):this
Sets the coordinates of this vector to the cross product of this vector and other.
Vector
Other vector.
this
crossed(
other):Vector
Returns a new vector resulting from taking the cross product of this vector and other.
Vector
Other vector.
Vector
divide(
scalar):this
Divides the coordinates of this vector by scalar.
number
Scalar value.
this
divided(
scalar):Vector
Returns a new vector resulting from dividing this vector by scalar.
number
Scalar value.
Vector
dot(
other):number
Returns the dot product of this vector and other.
Vector
Other vector.
number
staticfromXYZ(xyz):Vector
Creates a vector from an object implementing the BaseXYZ interface.
Object implementing BaseXYZ interface.
Vector
get(
index):number
Returns the coordinate value of the vector:
index equals 0index equals 1index equals 2Throws a RangeError if index is not in the range [0, 2].
number
Coordinate index.
number
isEqual(
other,tolerance?):boolean
Returns whether this vector is equal to other within the provided coordinate tolerance.
Vector
Other 3D vector.
number = Vector.coincidenceTolerance
Coordinate comparison tolerance (1e-7 by default).
boolean
isNormal(
other,tolerance?):boolean
Returns whether other is perpendicular to this vector within the provided angular tolerance.
Vector
Other vector.
number = Vector.angularTolerance
Angular comparison tolerance (1e-5 by default).
boolean
isOpposite(
other,tolerance?):boolean
Returns whether other is opposite to this vector within the provided angular tolerance.
Vector
Other vector.
number = Vector.angularTolerance
Angular comparison tolerance (1e-5 by default).
boolean
isParallel(
other,tolerance?):boolean
Returns whether other is parallel to this vector within the provided angular tolerance.
Vector
Other vector.
number = Vector.angularTolerance
Angular comparison tolerance (1e-5 by default).
boolean
length():
number
Returns the length of the vector.
number
mirror(
direction):this
Mirrors this vector about direction.
Direction.
this
mirror(
axis):this
Mirrors this vector about axis.
Axis.
this
mirror(
axis):this
Mirrors this vector about axis.
Axis.
this
mirrored(
direction):Vector
Returns a new vector resulting from mirroring this vector about direction.
Direction.
Vector
mirrored(
axis):Vector
Returns a new vector resulting from mirroring this vector about axis.
Axis.
Vector
mirrored(
axis):Vector
Returns a new vector resulting from mirroring this vector about axis.
Axis.
Vector
multiplied(
other):Vector
Returns a new vector resulting from multiplying this vector by other.
Vector
Other vector.
Vector
multiplied(
matrix):Vector
Returns a new vector resulting from multiplying this vector by matrix.
3D matrix.
Vector
multiplied(
scalar):Vector
Returns a new vector resulting from multiplying this vector by scalar.
number
Scalar value.
Vector
multiply(
other):this
Multiplies the coordinates of this vector by the coordinates of other component-wise.
Vector
Other vector.
this
multiply(
matrix):this
Multiplies the coordinates of this vector by a 3D matrix.
3D matrix.
this
multiply(
scalar):this
Multiplies the coordinates of this vector by a scalar value.
number
Scalar value.
this
normalize():
this
Normalizes the coordinates of this vector.
this
normalized():
Vector
Returns a new vector with normalized coordinates of this vector.
Vector
reverse():
this
Reverses the coordinates of this vector.
this
reversed():
Vector
Returns a new vector resulting from reversing this vector.
Vector
rotate(
axis,angle):this
Rotates this vector around axis by angle.
Rotation axis.
number
Rotation angle.
this
rotated(
axis,angle):Vector
Returns a new vector resulting from rotating this vector.
Rotation axis.
number
Rotation angle.
Vector
set(
index,value):this
Sets the coordinate value of the vector:
index equals 0index equals 1index equals 2Throws a RangeError if index is not in the range [0, 2].
number
Coordinate index.
number
Coordinate value.
this
setCoord(
x?,y?,z?):this
Sets the specified coordinates of the vector.
number
X coordinate of 3D vector.
number
Y coordinate of 3D vector.
number
Z coordinate of 3D vector.
this
setX(
x):this
Sets the X coordinate of the vector.
number
X coordinate.
this
setY(
y):this
Sets the Y coordinate of the vector.
number
Y coordinate.
this
setZ(
z):this
Sets the Z coordinate of the vector.
number
Z coordinate.
this
squareLength():
number
Returns the squared length of the vector.
number
subtract(
other):this
Subtracts the coordinates of other from this vector.
Vector
Other vector.
this
subtracted(
other):Vector
Returns a new vector resulting from subtracting other from this vector.
Vector
Other vector.
Vector
toJSON():
BaseXYZ
Returns the JSON representation of this vector.
toString(
precision?):string
Returns a string representation of this vector with the provided precision.
number = 3
Precision.
string
transform(
transformation):this
Transforms this vector according to transformation.
Only the rotation and scale factor of the transformation affect the vector. Translation is ignored.
Transformation.
this
transformed(
transformation):Vector
Returns a new vector resulting from transforming this vector.
Transformation.
Vector