Class: Vector
components.Vector
Represents a structure used to process vectors.
remarks
Note that the operations in this class will not modify the original vector,
except for the property assignments. This is to ensure that vectors are not
unintentionally modified.
example
const vectorA = new Vector(1, 3, 5);const vectorB = new Vector(2, 3, 1);const vectorC = vectorA.add(vectorB); // (3, 6, 6)
#
Constructors#
constructor• new Vector(x?
, y?
, z?
)
Creates a new vector with optional x-, y-, and z-components. Omitted components are defaulted to 0.
#
ParametersName | Type | Default value |
---|---|---|
x | number | 0 |
y | number | 0 |
z | number | 0 |
#
Defined in#
Properties#
forwardâ–ª Static
Readonly
forward: Vector
Returns (0, 0, 1).
#
Defined in#
oneâ–ª Static
Readonly
one: Vector
Returns (1, 1, 1).
#
Defined in#
rightâ–ª Static
Readonly
right: Vector
Returns (1, 0, 0).
#
Defined in#
upâ–ª Static
Readonly
up: Vector
Returns (0, 1, 0).
#
Defined in#
zeroâ–ª Static
Readonly
zero: Vector
Returns (0, 0, 0).
#
Defined in#
Accessors#
x• get
x(): number
Returns the x-component of the vector.
#
Returnsnumber
#
Defined in• set
x(value
): void
Modifies the x-component of the vector.
#
ParametersName | Type |
---|---|
value | number |
#
Returnsvoid
#
Defined in#
xyz• get
xyz(): [number
, number
, number
]
Returns the xyz-components of the vector, bundled as a copied array.
#
Returns[number
, number
, number
]
#
Defined in• set
xyz(values
): void
Simultaneously updates the xyz-components of the vector, by passing an array.
#
ParametersName | Type |
---|---|
values | [number , number , number ] |
#
Returnsvoid
#
Defined in#
y• get
y(): number
Returns the y-component of the vector.
#
Returnsnumber
#
Defined in• set
y(value
): void
Modifies the y-component of the vector.
#
ParametersName | Type |
---|---|
value | number |
#
Returnsvoid
#
Defined in#
z• get
z(): number
Returns the z-component of the vector.
#
Returnsnumber
#
Defined in• set
z(value
): void
Modifies the z-component of the vector.
#
ParametersName | Type |
---|---|
value | number |
#
Returnsvoid
#
Defined in#
Methods#
addâ–¸ add(vector
): Vector
Adds the two vectors together, component-wise.
#
ParametersName | Type |
---|---|
vector | Vector |
#
Returns#
Defined in#
angleâ–¸ angle(vector
): number
Returns the angle between two vectors, in degrees.
#
ParametersName | Type |
---|---|
vector | Vector |
#
Returnsnumber
#
Defined in#
crossâ–¸ cross(vector
): Vector
Returns the cross-product of two vectors.
#
ParametersName | Type |
---|---|
vector | Vector |
#
Returns#
Defined in#
dotâ–¸ dot(vector
): number
returns the dot-product of two vectors.
#
ParametersName | Type |
---|---|
vector | Vector |
#
Returnsnumber
#
Defined in#
magnitudeâ–¸ magnitude(): number
Returns the length of the vector.
#
Returnsnumber
#
Defined in#
normalizedâ–¸ normalized(): Vector
Normalizes the vector to a length of 1. If the length was previously zero, then a zero-length vector will be returned.
#
Returns#
Defined in#
scaleâ–¸ scale(scalar
): Vector
Scales the lefthand vector by another vector or by a number.
#
ParametersName | Type |
---|---|
scalar | number | Vector |
#
Returns#
Defined in#
sqrMagnitudeâ–¸ sqrMagnitude(): number
Returns the squared length of the vector.
#
Returnsnumber
#
Defined in#
subtractâ–¸ subtract(vector
): Vector
Subtracts the right vector from the left one, component-wise.
#
ParametersName | Type |
---|---|
vector | Vector |
#
Returns#
Defined in#
toStringâ–¸ toString(): string
Returns a formatted representation of the vector.
#
Returnsstring
#
Defined in#
from2dAngleâ–¸ Static
from2dAngle(angle
): Vector
Creates a new vector from an angle, in degrees. Note that the z-component will be zero.
#
ParametersName | Type |
---|---|
angle | number |