Readonly
xReadonly
xyReturns the x, y components of this. May be implemented as a getter method.
Readonly
yReadonly
zReturn 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)
$\approx \pi$
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)
Interpreting this vector as a point in ℝ³, returns the distance to the point
p
.
Equivalent to .minus(p).magnitude()
.
Computes the scalar product between this and v
.
In particular, a.dot(b)
is equivalent to a.x * b.x + a.y * b.y + a.z * b.z
.
[fuzz] The maximum difference between two components for this and [other] to be considered equal.
Optional
tolerance: numberVec3.of(1, 2, 3).eq(Vec3.of(4, 5, 6), 100); // → true
Vec3.of(1, 2, 3).eq(Vec3.of(4, 5, 6), 0.1); // → false
Vec3.of(1, 2, 3).eq(Vec3.of(4, 5, 6), 3); // → true
Vec3.of(1, 2, 3).eq(Vec3.of(4, 5, 6), 3.01); // → true
Vec3.of(1, 2, 3).eq(Vec3.of(4, 5, 6), 2.99); // → false
Returns a vector with each component acted on by fn
.
import { Vec3 } from '@js-draw/math'; console.log(Vec3.of(1, 2, 3).map(val => val + 1)); // → Vec(2, 3, 4)
Like normalized, except returns zero if this has zero magnitude.
Interpreting this vector as a point in ℝ^3, computes the square distance
to another point, p
.
Equivalent to .minus(p).magnitudeSquared()
.
zip
Maps a component of this and a corresponding component of
other
to a component of the output vector.
const a = Vec3.of(1, 2, 3);
const b = Vec3.of(0.5, 2.1, 2.9);
const zipped = a.zip(b, (aComponent, bComponent) => {
return Math.min(aComponent, bComponent);
});
console.log(zipped.toString()); // → Vec(0.5, 2, 2.9)
Generated using TypeDoc
A vector with three components, xyz. Can also be used to represent a two-component vector.
A
Vec3
is immutable.Example