public class Vector
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable
The internal fields are immutable - they are set once at the construction of the vector. All methods returning a vector construct a new vector.
The vector can be treated both in Cartesian and in polar form. Like below:
Constructor and Description |
---|
Vector()
Constructs the zero vector.
|
Vector(Angle angle,
double length)
Constructs a vector by polar coordinates.
|
Vector(double length,
Angle angle)
Constructs a vector by polar coordinates.
|
Vector(double x,
double y)
Constructs a vector by Cartesian coordinates (x,y).
|
Modifier and Type | Method and Description |
---|---|
Vector |
add(Vector v)
Addition of two vectors.
|
Vector |
clone() |
Vector |
collisionPointBetweenEllipses(Vector ellipseDimensionsOwn,
Angle orientationOwn,
Vector posOther,
Vector ellipseDimensionsOther,
Angle orientationOther)
Determines the collision surface normal from the rotated ellipse given by this
Vector
and the other given rotated ellipse. |
double |
distanceTo(Vector b)
Calculates the distance between two vectors.
|
double |
dotProduct(Vector b)
Dot product between two vectors (2D): a ° b.
|
boolean |
equals(java.lang.Object obj) |
Angle |
getAngle()
Gets the polar angle of this vector.
|
Angle |
getEllipseSurfaceNormal(Angle axisThroughCenter)
Calculates the surface normal for the ellipse given by this {@link Vector
|
double |
getLength()
Returns the length of this vector
|
Vector |
getNegative()
The inverse vector has same length and opposite direction.
|
Vector |
getNormal()
Scales this vector to a length of 1.
|
double |
getWeightedDiameterOfEllipse(Angle localAxesDir)
treat this vector as the dimensions of an ellipse and calculate the projected diameter.
|
double |
getX()
Returns the Cartesian x component.
|
double |
getY()
Returns the Cartesian y component.
|
int |
hashCode() |
boolean |
insideEllipse(Vector ellipse,
Vector ellipseCenter,
Angle ellipseOrientation)
Determines if this point (global coords) is inside an ellipse.
|
Vector |
mult(double factor)
Scales this vector by a given factor.
|
double |
projection(Angle angle)
Projects the vector onto a given Angle.
|
Vector |
rotate(Angle angle)
Rotates a vector in clockwise direction.
|
Vector |
sub(Vector v)
Subtracts a given vector from this vector.
|
java.lang.String |
toString() |
double |
vectorProduct(Vector b)
The vector product in the two dimensional space results in a scalar value.
|
public static final Vector ZERO
public Vector()
public Vector(Angle angle, double length)
angle
- length
- public Vector(double length, Angle angle)
length
- angle
- public Vector(double x, double y)
x
- doubley
- doublepublic Vector add(Vector v)
v
- Summandpublic Vector clone()
clone
in class java.lang.Object
public Vector collisionPointBetweenEllipses(Vector ellipseDimensionsOwn, Angle orientationOwn, Vector posOther, Vector ellipseDimensionsOther, Angle orientationOther)
Vector
and the other given rotated ellipse.ellipseDimensionsOwn
- - length and breadth of this ellipse; [m]; local axesorientationOwn
- posOther
- ellipseDimensionsOther
- - length and breadth of other ellipse; [m]; local axesorientationOther
- null
iff there is no collisionpublic double distanceTo(Vector b)
Note that the vectors must share the same reference system.
b
- Vectorpublic double dotProduct(Vector b)
b
- - second parameter of the dot productpublic boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public Angle getAngle()
public Angle getEllipseSurfaceNormal(Angle axisThroughCenter)
axisThroughCenter
- - local axespublic double getLength()
public Vector getNegative()
public Vector getNormal()
public double getWeightedDiameterOfEllipse(Angle localAxesDir)
localAxesDir
- - local axespublic double getX()
public double getY()
public int hashCode()
hashCode
in class java.lang.Object
public boolean insideEllipse(Vector ellipse, Vector ellipseCenter, Angle ellipseOrientation)
ellipse
- - local coords; x
is length, y
is breadthellipseCenter
- - global coordsfalse
iff the given point is outside of the ellipsepublic Vector mult(double factor)
factor
- public double projection(Angle angle)
angle
- - projection anglepublic Vector rotate(Angle angle)
angle
- rotation angle (>0 for clockwise rotation)public Vector sub(Vector v)
v
- Subtrahendpublic java.lang.String toString()
toString
in class java.lang.Object
public double vectorProduct(Vector b)
b
- - second parameter of the vector product