vector3.unit
The vector scaled to length 1, or null when it has no direction.
Usage
Vector3.unit(v: Vector3): Vector3 | nullParameters
vVector3The vector to normalise; any non-zero finite length. Required. In model.
Returns
A vector of length 1 in the direction of v; null when v has zero length or a non-finite length (NaN or infinite component).
Guarantees
- a non-null result has length 1 to within a few ulps (Math.abs(Vector3.length(u) - 1) < 1e-15)
- a non-null result points the same way as v (Vector3.angleRad(u, v) is 0 to rounding)
- null exactly when Vector3.length(v) is 0 or not finite
- The same result on every machine.
Example
Vector3.unit(Vector3.of(0, 0, -3)) // → { x: 0, y: 0, z: -1 }
Vector3.unit(Vector3.zero) // → null