Direction coordinates are always normalized.
new Direction(
x?,y?,z?):Direction
Creates a direction from coordinates.
If no arguments are provided, the direction is created with coordinates (0, 0, 1). If z is omitted while x or y is provided, z defaults to 0. The resulting coordinates are normalized.
Throws a RangeError if the resulting direction magnitude is not greater than 1e-5.
number
X coordinate of 3D direction.
number
Y coordinate of 3D direction.
number
Z coordinate of 3D direction.
Direction
get x():
number
Returns the X coordinate of the direction.
number
set x(
x):void
Sets the X coordinate of the direction and normalizes the result.
Throws a RangeError if the resulting direction magnitude is not greater than 1e-5.
number
X coordinate.
void
get y():
number
Returns the Y coordinate of the direction.
number
set y(
y):void
Sets the Y coordinate of the direction and normalizes the result.
Throws a RangeError if the resulting direction magnitude is not greater than 1e-5.
number
Y coordinate.
void
get z():
number
Returns the Z coordinate of the direction.
number
set z(
z):void
Sets the Z coordinate of the direction and normalizes the result.
Throws a RangeError if the resulting direction magnitude is not greater than 1e-5.
number
Z coordinate.
void
add(
other):this
Adds other direction to this direction and normalizes the result.
Throws a RangeError if the resulting direction magnitude is not greater than 1e-5.
Direction
Other direction.
this
added(
other):Direction
Returns a new direction obtained by applying add() to this direction.
Direction
Other direction.
Direction
angle(
other):number
Returns the angle between this and other direction.
Direction
Other direction.
number
clone():
Direction
Creates a new direction with the same coordinates as this direction.
Direction
copy(
other):this
Copies the coordinates of other to this direction.
Direction
Direction to copy.
this
cross(
other):this
Sets this direction to the cross product of this and other directions and normalizes the result.
Throws a RangeError if the resulting direction magnitude is not greater than 1e-5.
Direction
Other direction.
this
crossCross(
coord1,coord2):this
Computes this = this.cross(coord1.cross(coord2)).
Throws a RangeError if the resulting direction magnitude is not greater than 1e-5.
Direction
First direction.
Direction
Second direction.
this
crossCrossed(
coord1,coord2):Direction
Returns a new direction obtained by applying crossCross() to this direction.
Direction
First direction.
Direction
Second direction.
Direction
crossed(
other):Direction
Returns a new direction obtained by applying cross() to this direction.
Direction
Other direction.
Direction
dot(
other):number
Returns the dot product of this and other directions.
Direction
Other direction.
number
staticfromXYZ(xyz):Direction
Creates a direction from an object implementing BaseXYZ.
Object implementing BaseXYZ interface.
Direction
get(
index):number
Returns the coordinate value of the direction:
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 true if other direction is equal to this direction within the specified tolerance.
Direction
Other 3D direction.
number = Direction.angularTolerance
Angular comparison tolerance. Defaults to 1e-5.
boolean
isNormal(
other,tolerance?):boolean
Returns true if other direction is perpendicular to this direction within the specified tolerance.
Direction
Other direction.
number = Direction.angularTolerance
Angular comparison tolerance. Defaults to 1e-5.
boolean
isOpposite(
other,tolerance?):boolean
Returns true if other direction is opposite to this direction within the specified tolerance.
Direction
Other direction.
number = Direction.angularTolerance
Angular comparison tolerance. Defaults to 1e-5.
boolean
isParallel(
other,tolerance?):boolean
Returns true if other direction is parallel to this direction within the specified tolerance.
Direction
Other direction.
number = Direction.angularTolerance
Angular comparison tolerance. Defaults to 1e-5.
boolean
mirror(
direction):this
Mirrors this direction relative to direction.
Direction
Other direction.
this
mirror(
axis):this
Mirrors this direction relative to axis.
Axis.
this
mirror(
axis):this
Mirrors this direction relative to axis.
Axis.
this
mirrored(
direction):Direction
Returns a new direction obtained by applying mirror() to this direction.
Direction
Direction.
Direction
mirrored(
axis):Direction
Returns a new direction obtained by applying mirror() to this direction.
Axis.
Direction
mirrored(
axis):Direction
Returns a new direction obtained by applying mirror() to this direction.
Axis.
Direction
multiplied(
other):Direction
Returns a new direction obtained by applying multiply() to this direction.
Direction
Other direction.
Direction
multiplied(
matrix):Direction
Returns a new direction obtained by applying multiply() to this direction.
3D matrix.
Direction
multiply(
other):this
Multiplies the coordinates of this direction by the coordinates of other and normalizes the result.
Throws a RangeError if the resulting direction magnitude is not greater than 1e-5.
Direction
Other direction.
this
multiply(
matrix):this
Multiplies the coordinates of this direction by matrix and normalizes the result.
Throws a RangeError if the resulting direction magnitude is not greater than 1e-5.
3D matrix.
this
reverse():
this
Reverses this direction.
this
reversed():
Direction
Returns a new direction obtained by applying reverse() to this direction.
Direction
rotate(
axis,angle):this
Rotates this direction around axis by angle.
Rotation axis.
number
Rotation angle.
this
rotated(
axis,angle):Direction
Returns a new direction obtained by applying rotate() to this direction.
Rotation axis.
number
Rotation angle.
Direction
set(
index,value):this
Sets the coordinate value of the direction and normalizes the result:
index equals 0index equals 1index equals 2Throws a RangeError if index is not in the range [0, 2] or if the resulting direction magnitude is not greater than 1e-7.
number
Coordinate index.
number
Coordinate value.
this
setCoord(
x?,y?,z?):this
Sets the specified coordinates of the direction and normalizes the result.
Coordinates passed as undefined are left unchanged. Throws a RangeError if the resulting direction magnitude is not greater than 1e-5.
number
X coordinate of 3D direction.
number
Y coordinate of 3D direction.
number
Z coordinate of 3D direction.
this
setX(
x):this
Sets the X coordinate of the direction and normalizes the result.
Throws a RangeError if the resulting direction magnitude is not greater than 1e-5.
number
X coordinate.
this
setY(
y):this
Sets the Y coordinate of the direction and normalizes the result.
Throws a RangeError if the resulting direction magnitude is not greater than 1e-5.
number
Y coordinate.
this
setZ(
z):this
Sets the Z coordinate of the direction and normalizes the result.
Throws a RangeError if the resulting direction magnitude is not greater than 1e-5.
number
Z coordinate.
this
subtract(
other):this
Subtracts other direction from this direction and normalizes the result.
Throws a RangeError if the resulting direction magnitude is not greater than 1e-5.
Direction
Other direction.
this
subtracted(
other):Direction
Returns a new direction obtained by applying subtract() to this direction.
Direction
Other direction.
Direction
toJSON():
BaseXYZ
Returns a JSON-serializable representation of this direction.
toString(
precision?):string
Returns a string representation of this direction with the specified precision.
number = 3
Precision.
string
transform(
transformation):this
Transforms this direction according to transformation.
Only the rotational part of the transformation affects the direction. If the transformation scale factor is negative, the direction is reversed.
Transformation.
this
transformed(
transformation):Direction
Returns a new direction obtained by applying transform() to this direction.
Transformation.
Direction
staticxDir():Direction
Returns a direction with coordinates (1, 0, 0).
Direction
staticyDir():Direction
Returns a direction with coordinates (0, 1, 0).
Direction
staticzDir():Direction
Returns a direction with coordinates (0, 0, 1).
Direction