Field Summary
Fields
double
The x coordinate of this
Vector
.
double
The y coordinate of this
Vector
.
Constructor Summary
Constructors
Constructs a
Vector
that points in the specified direction.
Constructs a
Vector
representing the difference between two
provided
Vector
s.
Constructs a
Vector
representing the direction and magnitude
between to provided
Point
s.
Method Summary
All Methods Instance Methods Concrete Methods
boolean
Returns the smallest
Angle
between this
Vector
and the
provided one.
Returns the counter-clockwise (CCW)
Angle
between this
Vector
and the provided one.
Returns the clockwise (CW)
Angle
between this
Vector
and
the provided one.
Creates a new
Vector
which represents the average of this
Vector
with the provided one.
Returns a copy of this
Vector
object.
double
Calculates the cross product of this
Vector
(lhs) and the given
other
Vector
(rhs).
double
Calculates the magnitude of the cross product of this
Vector
with
the given other
Vector
.
Creates a new
Vector
which represents this
Vector
divided
by the provided scalar value.
double
Calculates the dot product of this
Vector
and the given other
Vector
.
double
Returns the length of this
Vector
.
Creates a new
Vector
which represents this
Vector
multiplied by the provided scalar value.
Creates a new
Vector
that has the same direction as this
Vector
and a length of 1.
Returns the orthogonal complement of this
Vector
, which is
defined to be (-y, x).
Returns a new
Vector
which corresponds to this
Vector
after rotating it counter-clockwise (CCW) by the given
Angle
.
Returns a new
Vector
which corresponds to this
Vector
after rotating it clockwise (CW) by the given
Angle
.
double
Calculates the similarity of this
Vector
and the provided one.
Returns a new
Vector
that represents the difference of this
Vector
and the provided one.
int
boolean
Checks if this
Vector
is horizontal, i.e. whether its horizontal
component (the x coordinate) does not equal 0, while its vertical
component (the y coordinate) does.
boolean
Checks if this
Vector
's x and y coordinates are equal to 0.
boolean
Checks if this
Vector
and the provided one are orthogonal to each
other.
boolean
Checks if this
Vector
and the provided one are parallel to each
other.
boolean
Checks if this
Vector
is vertical, i.e. whether its vertical
component (the x coordinate) does not equal 0, while its horizontal
component (the y coordinate) does.
Rotates this
Vector
counter-clockwise (CCW) by the given
Angle
.
Field Details
NULL
public static final Vector NULL
The (0,0) vector.
x
public double x
The x coordinate of this
Vector
.
y
public double y
The y coordinate of this
Vector
.
Constructor Details
Vector
public Vector (double x,
double y)
Constructs a
Vector
that points in the specified direction.
Parameters:
x
- x coordinate
y
- y coordinate
Vector
Parameters:
p
- the Point
to construct a position Vector
for
Vector
Constructs a
Vector
representing the direction and magnitude
between to provided
Point
s.
Parameters:
start
- the start Point
end
- the end Point
Vector
Constructs a
Vector
representing the difference between two
provided
Vector
s.
Parameters:
start
- the start Vector
end
- the end Vector
Method Details
getAdded
Parameters:
other
- the Vector
that is added to this Vector
Returns:
a new Vector
representing the sum of this Vector
and the given other Vector
getAngle
Returns the smallest
Angle
between this
Vector
and the
provided one.
Parameters:
other
- the Vector
for which the smallest Angle
to
this Vector
is calculated
Returns:
the smallest Angle
between this Vector
and the
provided one
getAngleCCW
Returns the counter-clockwise (CCW)
Angle
between this
Vector
and the provided one.
Parameters:
other
- the Vector
for which the CCW Angle
to this
Vector
is calculated
Returns:
the counter-clockwise Angle
between this Vector
and the provided one
getAngleCW
Returns the clockwise (CW)
Angle
between this
Vector
and
the provided one.
Parameters:
other
- the Vector
for which the CW Angle
to this
Vector
is calculated
Returns:
the clockwise Angle
between this Vector
and the
provided one
getAveraged
Creates a new
Vector
which represents the average of this
Vector
with the provided one.
Parameters:
other
- the Vector
for which the average with this
Vector
is calculated
Returns:
a new Vector
which represents the average of this
Vector
and the provided one
getCopy
Returns a copy of this
Vector
object.
Returns:
a copy of this Vector
object
getCrossProduct
public double getCrossProduct (Vector other)
Calculates the cross product of this
Vector
(lhs) and the given
other
Vector
(rhs).
Parameters:
other
- the rhs Vector
for which the cross product with this
Vector
is calculated
Returns:
the cross product of this Vector
(lhs) and the given
other Vector
(rhs)
getDissimilarity
public double getDissimilarity (Vector other)
Calculates the magnitude of the cross product of this
Vector
with
the given other
Vector
. This method normalizes both
Vector
s before calculating the cross product. The resulting
dissimilarity value represents the amount by which two
Vector
s
are directionally different. For parallel
Vector
s 0 is returned.
Parameters:
other
- the Vector
to compare to this Vector
Returns:
the dissimilarity of both Vector
s
getDivided
public Vector getDivided (double factor)
Creates a new
Vector
which represents this
Vector
divided
by the provided scalar value.
Parameters:
factor
- the divisor
Returns:
a new Vector
which represents this Vector
divided
by the provided scalar value
getDotProduct
public double getDotProduct (Vector other)
Calculates the dot product of this
Vector
and the given other
Vector
.
Parameters:
other
- the Vector
for which the dot product with this
Vector
is calculated
Returns:
the dot product of the two Vector
s
getLength
public double getLength ()
Returns the length of this
Vector
.
Returns:
the length of this Vector
getMultiplied
public Vector getMultiplied (double factor)
Creates a new
Vector
which represents this
Vector
multiplied by the provided scalar value.
Parameters:
factor
- the scalar multiplication factor to scale this Vector
Returns:
a new Vector
which represents this Vector
multiplied by the provided scalar value
getNormalized
Creates a new
Vector
that has the same direction as this
Vector
and a length of 1.
Returns:
a new Vector
with the same direction as this
Vector
and a length of 1
getOrthogonalComplement
public Vector getOrthogonalComplement ()
Returns the orthogonal complement of this
Vector
, which is
defined to be (-y, x).
Returns:
the orthogonal complement of this Vector
getRotatedCCW
Returns a new
Vector
which corresponds to this
Vector
after rotating it counter-clockwise (CCW) by the given
Angle
.
Parameters:
angle
- the rotation Angle
Returns:
a new Vector
which represents the result of the CCW
rotation of this Vector
getRotatedCW
Returns a new
Vector
which corresponds to this
Vector
after rotating it clockwise (CW) by the given
Angle
.
Parameters:
angle
- the rotation Angle
Returns:
a new Vector
which represents the result of the CW
rotation of this Vector
getSimilarity
public double getSimilarity (Vector other)
Calculates the similarity of this
Vector
and the provided one.
The similarity is defined as the absolute value of the dotProduct(). For
orthogonal
Vector
s, 0 is returned.
Parameters:
other
- the Vector
for which the similarity to this
Vector
is calculated
Returns:
the similarity of this Vector
and the provided one
See Also:
getSubtracted
Returns a new
Vector
that represents the difference of this
Vector
and the provided one.
Parameters:
other
- the Vector
that is subtracted from this Vector
Returns:
a new Vector
representing the difference of this
Vector
and the provided one
hashCode
public int hashCode ()
Overrides:
hashCode
in class Object
See Also:
isHorizontal
public boolean isHorizontal ()
Checks if this
Vector
is horizontal, i.e. whether its horizontal
component (the x coordinate) does not equal 0, while its vertical
component (the y coordinate) does.
Returns:
true
if this Vector
's x coordinate does not
equal 0 and this Vector
's y coordinate does equal 0,
otherwise false
isNull
public boolean isNull ()
Checks if this
Vector
's x and y coordinates are equal to 0.
Returns:
true
if this Vector
's x and y coordinates
are equal to 0, otherwise false
isOrthogonalTo
public boolean isOrthogonalTo (Vector other)
Checks if this
Vector
and the provided one are orthogonal to each
other.
Parameters:
other
- the Vector
which is checked for orthogonality to this
Vector
Returns:
true
if this Vector
and the provided one are
orthogonal to each other, otherwise false
isParallelTo
public boolean isParallelTo (Vector other)
Checks if this
Vector
and the provided one are parallel to each
other.
Parameters:
other
- the Vector
that is checked to be parallel to this
Vector
Returns:
true
if this Vector
and the provided one are
parallel, otherwise false
isVertical
public boolean isVertical ()
Checks if this
Vector
is vertical, i.e. whether its vertical
component (the x coordinate) does not equal 0, while its horizontal
component (the y coordinate) does.
Returns:
true
if this Vector
's y coordinate does not
equal 0 and this Vector
's x coordinate does equal 0,
rotateCCW
Rotates this
Vector
counter-clockwise (CCW) by the given
Angle
.
Parameters:
angle
- the rotation Angle
Returns:
this
for convenience
rotateCW
Parameters:
angle
- the rotation Angle
Returns:
this
for convenience