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
.
Optional
tolerance: numberThe maximum difference between two components for this and [other] to be considered equal.
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.
A vector with three components, xyz. Can also be used to represent a two-component vector.
A
Vec3
is immutable.Example