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
var v = v1.cross(v2).dot(v3) // ≡ v1×v2⋅v3
Members
length
Length (magnitude or norm) of ‘this’ vector
- Source:
Methods
angleTo(v, vSignopt) → {number}
Calculates the angle between ‘this’ vector and supplied vector.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
v |
Vector3d | ||
vSign |
Vector3d |
<optional> |
If supplied (and out of plane of this and v), angle is signed +ve if this->v is clockwise looking along vSign, -ve in opposite direction (otherwise unsigned angle). |
- Source:
Returns:
Angle (in radians) between this vector and supplied vector.
- 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