Class Vector

An immutable vector in 3D space; after creation it cannot be altered.

Constructors

• Parameters

• x: number

the X value of the Vector

• y: number

the Y value of the Vector

• `Optional`opt_z: number

the Z value of the Vector (optional, zero is default value)

Properties

lengthSquared_: number

Cache of lengthSquared.

length_: number

Cache of length.

EAST: Vector = ...

The vector `(1, 0, 0)`.

NORTH: Vector = ...

The vector `(0, 1, 0)`.

ORIGIN: Vector = ...

The vector `(0, 0, 0)`.

SOUTH: Vector = ...

The vector `(0, -1, 0)`.

TINY_POSITIVE: 1e-10 = 1E-10

Very small number used to detect zero length vectors in divide and normalize.

WEST: Vector = ...

The vector `(-1, 0, 0)`.

Methods

• Returns sum of this Vector and given GenericVector.

Returns Vector

sum of this Vector and given Vector

• Returns the angle going from this vector to another vector when both vectors are arranged so they start at the origin.

Parameters

• vector: GenericVector

the other vector

Returns number

angle from this vector to other vector in radians; positive means counterclockwise.

• Returns distance-squared between this Vector and another GenericVector regarding both as points in space. Computationally inexpensive because it only uses multiplication, no square root.

Parameters

• point: GenericVector

vector to calculate distance to

Returns number

distance squared between this point and the given point

• Returns distance between this Vector and another GenericVector regarding both as points in space. Computationally expensive because it involves as square root.

Parameters

• point: GenericVector

the Vector to calculate distance to

Returns number

distance between this Vector and the given point

• Returns this Vector divided by the given factor.

Parameters

• factor: number

factor by which to divide this Vector

Returns Vector

quotient of this vector and given factor

Throws

if factor is less than TINY_POSITIVE

• Returns the dot product of this Vector and the given vector.

Parameters

• vector: GenericVector

the vector with which to form a dot product

Returns number

the dot product of this Vector and the given vector

• Returns true iff the other object is a GenericVector with the same values.

Parameters

• vector: GenericVector

the object to compare to

Returns boolean

true iff the other object is a GenericVector with the same values.

• Returns the angle `theta` from the conversion of rectangular coordinates `(x, y)` to polar coordinates `(r, theta)`.

Returns number

the angle of this Vector in the `x-y` plane using mathematical angle convention in radians in range from `-pi` to `pi`.

• Returns length of this Vector. Note this is computationally expensive as it involves taking a square root.

Returns number

length of this Vector

• Computationally cheap version of length which avoids the square root; returns sum of absolute value of each component `x, y, z`.

Returns number

sum of absolute value of each component `x, y, z`.

• Returns length squared of this Vector. Computationally cheap because it only uses multiplication, no square root.

Returns number

length squared of this Vector

• Returns this Vector multiplied by the given factor.

Parameters

• factor: number

factor by which to multiply this Vector

Returns Vector

product of this Vector and given factor

• Returns `true` if this Vector is nearly equal to another Vector. The optional tolerance value corresponds to the `epsilon` in Util.veryDifferent so the actual tolerance used depends on the magnitude of the numbers being compared.

Parameters

• vector: GenericVector

the vector to compare to

• `Optional`opt_tolerance: number

optional tolerance for equality test

Returns boolean

true if the vectors are similar

• Returns the normalized version of this Vector, having unit length and the same direction.

Returns Vector

normalized version of this Vector, having unit length and the same direction

Throws

if this Vector has length less than TINY_POSITIVE

• Returns this Vector rotated counter-clockwise about the origin by the given angle in radians. If two parameters are given then they are the cosine and sine of the angle (this avoids calculating the sine and cosine which is computationally expensive).

Parameters

• angle: number

the angle in radians by which to rotate this Vector, or the cosine of the angle when two parameters are given

• `Optional`sineAngle: number

the sine of the angle, when two parameters are given

Returns Vector

this Vector rotated counter-clockwise about the origin

• Returns difference of this Vector and given Vector.

Parameters

• vector: GenericVector

the vector to subtract

Returns Vector

difference of this Vector and given vector

• Returns an immutable Vector having the same values as the input GenericVector. If the input vector is an immutable Vector, returns that same Vector.

Parameters

• vector: GenericVector

the GenericVector to copy

Returns Vector

an immutable Vector with the same values as the input GenericVector

Generated using TypeDoc