DWVv0.37.0

Vector3D

Source: vector.js:4

Immutable 3D vector.


Constructor

new Vector3D(x: number, y: number, z: number): Vector3D

Parameters

  • x (number) — The X component of the vector.
  • y (number) — The Y component of the vector.
  • z (number) — The Z component of the vector.

Instance Methods

getX(): number

Get the X component of the vector.

Returns

  • number — The X component of the vector.

getY(): number

Get the Y component of the vector.

Returns

  • number — The Y component of the vector.

getZ(): number

Get the Z component of the vector.

Returns

  • number — The Z component of the vector.

equals(rhs: Vector3D): boolean

Check for Vector3D equality.

Parameters

  • rhs (Vector3D) — The other vector to compare to.

Returns

  • boolean — True if both vectors are equal.

toString(): string

Get a string representation of the Vector3D.

Returns

  • string — The vector as a string.

norm(): number

Get the norm of the vector.

Returns

  • number — The norm.

crossProduct(vector3D: Vector3D): Vector3D

Get the cross product with another Vector3D, ie the vector that is perpendicular to both a and b. If both vectors are parallel, the cross product is a zero vector.

Ref: https://en.wikipedia.org/wiki/Cross_product.

Parameters

  • vector3D (Vector3D) — The input vector.

Returns

dotProduct(vector3D: Vector3D): number

Get the dot product with another Vector3D.

Ref: https://en.wikipedia.org/wiki/Dot_product.

Parameters

  • vector3D (Vector3D) — The input vector.

Returns

  • number — The dot product.

isCodirectional(vector3D: Vector3D): boolean

Is this vector codirectional to an input one.

Parameters

  • vector3D (Vector3D) — The vector to test.

Returns

  • boolean — True if codirectional, false is opposite.