ReadonlyxReadonlyxyReturns the x, y components of this. May be implemented as a getter method.
ReadonlyyReadonlyzReturn this' angle in the XY plane (treats this as a Vec2).
This is equivalent to Math.atan2(vec.y, vec.x).
As such, observing that Math.atan2(-0, -1) and Math.atan2(0, -1)
the resultant angle is in the range .
Example:
import { Vec2 } from '@js-draw/math';
console.log(Vec2.of(-1, -0).angle()); // atan2(-0, -1)
console.log(Vec2.of(-1, 0).angle()); // atan2(0, -1)
Like normalized, except returns zero if this has zero magnitude.
A vector with three components, xyz. Can also be used to represent a two-component vector.
A
Vec3is immutable.Example
import { Vec3 } from '@js-draw/math'; console.log('Vector addition:', Vec3.of(1, 2, 3).plus(Vec3.of(0, 1, 0))); console.log('Scalar multiplication:', Vec3.of(1, 2, 3).times(2)); console.log('Cross products:', Vec3.unitX.cross(Vec3.unitY)); console.log('Magnitude:', Vec3.of(1, 2, 3).length(), 'or', Vec3.of(1, 2, 3).magnitude()); console.log('Square Magnitude:', Vec3.of(1, 2, 3).magnitudeSquared()); console.log('As an array:', Vec3.unitZ.asArray());