Tuple2DReadOnly
Vector2DBasics
Vector2D
, Vector2D32
public interface Vector2DReadOnly extends Tuple2DReadOnly
A 2D vector represents a physical quantity with a magnitude and a direction in the XY-plane. For instance, it can be used to represent a 2D velocity, force, or translation from one 2D point to another.
Although a point and vector hold onto the same type of information, the distinction is made between them as they represent different geometry objects and are typically not handled the same way:
Modifier and Type | Method | Description |
---|---|---|
default double |
angle(Vector2DReadOnly other) |
Calculates and returns the angle in radians from this vector to
other . |
default double |
cross(Tuple2DReadOnly tuple) |
Calculates and returns the value of the cross product of this vector with
tuple . |
static double |
cross(Tuple2DReadOnly tuple1,
Tuple2DReadOnly tuple2) |
Calculates and returns the value of the cross product of
tuple1 with tuple2 . |
default double |
dot(Vector2DReadOnly other) |
Calculates and returns the value of the dot product of this vector with
other . |
default boolean |
geometricallyEquals(Vector2DReadOnly other,
double epsilon) |
Tests if
this and other represent the same vector 2D to an epsilon . |
default double |
length() |
Calculates and returns the magnitude of this vector.
|
default double |
lengthSquared() |
Calculates and returns the square of the magnitude of this vector.
|
containsNaN, epsilonEquals, equals, get, get, get, get, get, get, get, getElement, getElement32, getX, getX32, getY, getY32
default double length()
length = √(x2 + y2)
default double lengthSquared()
length2 = x2 + y2
This method is usually preferred over length()
when calculation speed matters and
knowledge of the actual magnitude does not, i.e. when comparing several vectors by theirs
magnitude.
default double dot(Vector2DReadOnly other)
other
.
For instance, the dot product of two vectors p and q is defined as:
p . q = ∑i=1:2(pi * qi)
other
- the other vector used for the dot product. Not modified.default double angle(Vector2DReadOnly other)
other
.
The computed angle is in the range [-pi; pi].
other
- the other vector used to compute the angle. Not modified.other
.default double cross(Tuple2DReadOnly tuple)
tuple
.tuple
- the second term in the cross product. Not modified.static double cross(Tuple2DReadOnly tuple1, Tuple2DReadOnly tuple2)
tuple1
with tuple2
.tuple1
- the first tuple in the cross product. Not modified.tuple2
- the second tuple in the cross product. Not modified.default boolean geometricallyEquals(Vector2DReadOnly other, double epsilon)
this
and other
represent the same vector 2D to an epsilon
.
Two vectors are considered geometrically equal if the length of their difference is less than
or equal to epsilon
.
Note that this.geometricallyEquals(other, epsilon) == true
does not necessarily imply
this.epsilonEquals(other, epsilon)
and vice versa.
other
- the other vector 2D to compare against this. Not modified.epsilon
- the maximum length of the difference vector can be for the two vectors to be
considered equal.true
if the two vectors represent the same geometry, false
otherwise.