Clearable
, EpsilonComparable<Vector2D>
, GeometricallyComparable<Vector2D>
, GeometryObject<Vector2D>
, Settable<Vector2D>
, Transformable
, Tuple2DBasics
, Tuple2DReadOnly
, Vector2DBasics
, Vector2DReadOnly
public class Vector2D extends java.lang.Object implements Vector2DBasics, GeometryObject<Vector2D>
This version of 2D vector uses double precision fields to save the value of each component. It is meant for garbage free usage.
Constructor | Description |
---|---|
Vector2D() |
Creates a new vector and initializes it components to zero.
|
Vector2D(double[] vectorArray) |
Creates a new vector and initializes its component
x , y in order from the
given array. |
Vector2D(double x,
double y) |
Creates a new vector and initializes it with the given components.
|
Vector2D(Tuple2DReadOnly other) |
Creates a new vector and initializes it to
other . |
Vector2D(Tuple3DReadOnly tuple3DReadOnly) |
Creates a new vector and initializes it to
tuple3DReadOnly x and y components. |
Modifier and Type | Method | Description |
---|---|---|
boolean |
epsilonEquals(Vector2D other,
double epsilon) |
Tests on a per component basis if this vector is equal to the given
other to an
epsilon . |
boolean |
equals(java.lang.Object object) |
Tests if the given
object 's class is the same as this, in which case the method
returns Tuple2DReadOnly.equals(Tuple2DReadOnly) , it returns false otherwise. |
boolean |
geometricallyEquals(Vector2D other,
double epsilon) |
Tests if
this and other represent the same vector 2D to an epsilon . |
double |
getX() |
Returns the value of the x-component of this vector.
|
double |
getY() |
Returns the value of the y-component of this vector.
|
int |
hashCode() |
Calculates and returns a hash code value from the value of each component of this vector 2D.
|
void |
set(Vector2D other) |
Sets this vector to
other . |
void |
setX(double x) |
Sets the x-component of this vector.
|
void |
setY(double y) |
Sets the y-component of this vector.
|
java.lang.String |
toString() |
Provides a
String representation of this vector 2D as follows: (x, y). |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
absolute, add, add, add, addX, addY, clipToMax, clipToMin, clipToMinMax, containsNaN, interpolate, interpolate, negate, scale, scale, scaleAdd, scaleAdd, scaleSub, scaleSub, set, set, set, set, set, set, set, set, set, set, setAndAbsolute, setAndClipToMax, setAndClipToMin, setAndClipToMinMax, setAndNegate, setAndScale, setElement, setToNaN, setToZero, sub, sub, sub, subX, subY
epsilonEquals, equals, get, get, get, get, get, get, get, getElement, getElement32, getX32, getY32
applyInverseTransform, applyInverseTransform, applyTransform, applyTransform, clipToMaxLength, normalize, setAndNormalize
angle, cross, dot, geometricallyEquals, length, lengthSquared
public Vector2D()
public Vector2D(double x, double y)
x
- the x-component.y
- the y-component.public Vector2D(double[] vectorArray)
x
, y
in order from the
given array.vectorArray
- the array containing this vector's components. Not modified.public Vector2D(Tuple2DReadOnly other)
other
.other
- the tuple to copy the components from. Not modified.public Vector2D(Tuple3DReadOnly tuple3DReadOnly)
tuple3DReadOnly
x and y components.tuple3DReadOnly
- the tuple to copy the coordinates from. Not modified.public void set(Vector2D other)
other
.public void setX(double x)
setX
in interface Tuple2DBasics
x
- the x-component.public void setY(double y)
setY
in interface Tuple2DBasics
y
- the y-component.public double getX()
getX
in interface Tuple2DReadOnly
public double getY()
getY
in interface Tuple2DReadOnly
public boolean equals(java.lang.Object object)
object
's class is the same as this, in which case the method
returns Tuple2DReadOnly.equals(Tuple2DReadOnly)
, it returns false
otherwise.equals
in class java.lang.Object
object
- the object to compare against this. Not modified.true
if object
and this are exactly equal, false
otherwise.public boolean epsilonEquals(Vector2D other, double epsilon)
other
to an
epsilon
.epsilonEquals
in interface EpsilonComparable<Vector2D>
other
- the other vector to compare against this. Not modified.epsilon
- the tolerance to use when comparing each component.true
if the two tuples are equal, false
otherwise.public boolean geometricallyEquals(Vector2D 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.
geometricallyEquals
in interface GeometricallyComparable<Vector2D>
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.public java.lang.String toString()
String
representation of this vector 2D as follows: (x, y).toString
in class java.lang.Object
String
representing this vector 2D.public int hashCode()
hashCode
in class java.lang.Object