Package org.eclipse.draw2d.geometry
Class Vector
java.lang.Object
org.eclipse.draw2d.geometry.Vector
Represents a vector within 2-dimensional Euclidean space.
- Since:
- 3.6
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionVector
(double x, double y) Constructs a Vector pointed in the specified direction.Constructs a Vector pointed in the direction specified by a Point.Vector
(PrecisionPoint start, PrecisionPoint end) Constructs a Vector representing the direction and magnitude between to provided Points.Constructs a Vector representing the difference between two provided Vectors. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Creates a new Vector which is the sum of this Vector with another.double
Returns the angle (in degrees) between this Vector and the provided Vector.getAveraged
(Vector other) Creates a new Vector which represents the average of this Vector with another.double
getCrossProduct
(Vector other) Calculates the cross product of this Vector with another.double
getDissimilarity
(Vector other) Calculates the magnitude of the cross product of this Vector with another.getDivided
(double factor) Creates a new Vector which represents this Vector divided by the provided scalar factor.double
getDotProduct
(Vector other) Calculates the dot product of this Vector with another.double
Returns the length of this Vector.getMultiplied
(double factor) Creates a new Vector which represents this Vector multiplied by the provided scalar factor.Returns the orthogonal complement of this Vector, which is defined to be (-y, x).double
getSimilarity
(Vector other) Calculates the similarity of this Vector with another.getSubtracted
(Vector other) Creates a new Vector which is the difference of this Vector with the provided Vector.int
hashCode()
boolean
Checks whether this vector has a horizontal component.boolean
isNull()
Checks whether this vector equals (0,0);boolean
isOrthogonalTo
(Vector other) Calculates whether this Vector and the provided one are orthogonal to each other.boolean
isParallelTo
(Vector other) Calculates whether this Vector and the provided one are parallel to each other.boolean
Checks whether this vector has a vertical component.toPoint()
Returns a point representation of this Vector.toString()
-
Field Details
-
x
public double xthe X value -
y
public double ythe Y value
-
-
Constructor Details
-
Vector
public Vector(double x, double y) Constructs a Vector pointed in the specified direction.- Parameters:
x
- X value.y
- Y value.
-
Vector
Constructs a Vector pointed in the direction specified by a Point.- Parameters:
p
- the point
-
Vector
Constructs a Vector representing the direction and magnitude between to provided Points.- Parameters:
start
- starting pointend
- End Point
-
Vector
Constructs a Vector representing the difference between two provided Vectors.- Parameters:
start
- The start Rayend
- The end Ray
-
-
Method Details
-
getDissimilarity
Calculates the magnitude of the cross product of this Vector with another. Represents the amount by which two Vectors are directionally different. Parallel Vectors return a value of 0.- Parameters:
other
- Vector being compared- Returns:
- The dissimilarity
-
isParallelTo
Calculates whether this Vector and the provided one are parallel to each other.- Parameters:
other
- The Vector to test for parallelism- Returns:
- true if this Vector and the provided one are parallel, false otherwise.
-
getDotProduct
Calculates the dot product of this Vector with another.- Parameters:
other
- the Vector used to calculate the dot product- Returns:
- The dot product
-
getCrossProduct
Calculates the cross product of this Vector with another.- Parameters:
other
- the Vector used to calculate the cross product- Returns:
- The cross product.
-
getAdded
Creates a new Vector which is the sum of this Vector with another.- Parameters:
other
- Vector to be added to this Vector- Returns:
- a new Vector representing the sum
-
getSubtracted
Creates a new Vector which is the difference of this Vector with the provided Vector.- Parameters:
other
- Vector to be subtracted from this Vector- Returns:
- a new Vector representing the difference.
-
getAngle
Returns the angle (in degrees) between this Vector and the provided Vector.- Parameters:
other
- Vector to calculate the angle.- Returns:
- the angle between the two Vectors in degrees.
-
getAveraged
Creates a new Vector which represents the average of this Vector with another.- Parameters:
other
- Vector to calculate the average.- Returns:
- a new Vector
-
getMultiplied
Creates a new Vector which represents this Vector multiplied by the provided scalar factor.- Parameters:
factor
- Value providing the amount to scale.- Returns:
- a new Vector
-
getDivided
Creates a new Vector which represents this Vector divided by the provided scalar factor.- Parameters:
factor
- Value providing the amount to scale.- Returns:
- a new Vector
-
getOrthogonalComplement
Returns the orthogonal complement of this Vector, which is defined to be (-y, x).- Returns:
- the orthogonal complement of this Vector
-
getLength
public double getLength()Returns the length of this Vector.- Returns:
- Length of this Vector
-
getSimilarity
Calculates the similarity of this Vector with another. Similarity is defined as the absolute value of the dotProduct(). Orthogonal vectors return a value of 0.- Parameters:
other
- Vector being tested for similarity- Returns:
- the Similarity
- See Also:
-
isOrthogonalTo
Calculates whether this Vector and the provided one are orthogonal to each other.- Parameters:
other
- Vector being tested for orthogonality- Returns:
- true, if this Vector and the provide one are orthogonal, false otherwise
-
isHorizontal
public boolean isHorizontal()Checks whether this vector has a horizontal component.- Returns:
- true if x != 0, false otherwise.
-
isVertical
public boolean isVertical()Checks whether this vector has a vertical component.- Returns:
- true if y != 0, false otherwise.
-
isNull
public boolean isNull()Checks whether this vector equals (0,0);- Returns:
- true if x == 0 and y == 0.
-
toPoint
Returns a point representation of this Vector.- Returns:
- a PrecisionPoint representation
-
toString
-
equals
-
hashCode
public int hashCode()
-