Class: Vector3d

vector3d~Vector3d(x, y, z)

Functions for manipulating generic 3-d vectors. Functions return vectors as return results, so that operations can be chained.

Constructor

new Vector3d(x, y, z)

Creates a 3-d vector.
Parameters:
Name Type Description
x number X component of vector.
y number Y component of vector.
z number Z component of vector.
Source:
Example
const v = v1.cross(v2).dot(v3) // ≡ v1×v2⋅v3

Members

length

Length (magnitude or norm) of ‘this’ vector.
Source:

Methods

angleTo(v, nopt) → {number}

Calculates the angle between ‘this’ vector and supplied vector atan2(|p₁×p₂|, p₁·p₂) (or if (extra-planar) ‘n’ supplied then atan2(n·p₁×p₂, p₁·p₂).
Parameters:
Name Type Attributes Description
v Vector3d Vector whose angle is to be determined from ‘this’ vector.
n Vector3d <optional>
Plane normal: if supplied, angle is signed +ve if this->v is clockwise looking along n, -ve in opposite direction.
Source:
Returns:
Angle (in radians) between this vector and supplied vector (in range 0..π if n not supplied, range -π..+π if n supplied).
Type
number

cross(v) → {Vector3d}

Multiplies ‘this’ vector by the supplied vector using cross (vector) product.
Parameters:
Name Type Description
v Vector3d Vector to be crossed with this vector.
Source:
Returns:
Cross product of ‘this’ and v.
Type
Vector3d

dividedBy(x) → {Vector3d}

Divides ‘this’ vector by a scalar value.
Parameters:
Name Type Description
x number Factor to divide this vector by.
Source:
Returns:
Vector divided by x.
Type
Vector3d

dot(v) → {number}

Multiplies ‘this’ vector by the supplied vector using dot (scalar) product.
Parameters:
Name Type Description
v Vector3d Vector to be dotted with this vector.
Source:
Returns:
Dot product of ‘this’ and v.
Type
number

minus(v) → {Vector3d}

Subtracts supplied vector from ‘this’ vector.
Parameters:
Name Type Description
v Vector3d Vector to be subtracted from this vector.
Source:
Returns:
Vector representing difference between this and v.
Type
Vector3d

negate() → {Vector3d}

Negates a vector to point in the opposite direction.
Source:
Returns:
Negated vector.
Type
Vector3d

plus(v) → {Vector3d}

Adds supplied vector to ‘this’ vector.
Parameters:
Name Type Description
v Vector3d Vector to be added to this vector.
Source:
Returns:
Vector representing sum of this and v.
Type
Vector3d

rotateAround(axis, angle) → {Vector3d}

Rotates ‘this’ point around an axis by a specified angle.
Parameters:
Name Type Description
axis Vector3d The axis being rotated around.
angle number The angle of rotation (in degrees).
Source:
Returns:
The rotated point.
Type
Vector3d

times(x) → {Vector3d}

Multiplies ‘this’ vector by a scalar value.
Parameters:
Name Type Description
x number Factor to multiply this vector by.
Source:
Returns:
Vector scaled by x.
Type
Vector3d

toString(dpopt) → {string}

String representation of vector.
Parameters:
Name Type Attributes Default Description
dp number <optional>
3 Number of decimal places to be used.
Source:
Returns:
Vector represented as [x,y,z].
Type
string

unit() → {Vector3d}

Normalizes a vector to its unit vector – if the vector is already unit or is zero magnitude, this is a no-op.
Source:
Returns:
Normalised version of this vector.
Type
Vector3d