Skip to main content

Vector

From v1.1

Vector is the base class for Vector2, Vector3, and Vector4. It extends MathArray and JavaScript Array; use a concrete vector class.

Magnitude and distanceโ€‹

MethodResult
len() or magnitude()Vector magnitude
lengthSquared() or magnitudeSquared()Squared magnitude
distance(other)Euclidean distance to another vector
distanceSquared(other)Squared distance
dot(other)Dot product

vector.length is the number of components. It is not callable.

Mutating operationsโ€‹

normalize()โ€‹

Scales a nonzero vector to unit magnitude and leaves a zero vector unchanged. multiply(...vectors) and divide(...vectors) operate component by component.

Copying, addition, subtraction, scaling, interpolation, comparisons, and validation are documented on MathArray. Mutating methods return the receiver.