Class Vector

java.lang.Object
org.eclipse.draw2d.geometry.Vector

public class Vector extends Object
Represents a vector within 2-dimensional Euclidean space.
Since:
3.6
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    double
    the X value
    double
    the Y value
  • Constructor Summary

    Constructors
    Constructor
    Description
    Vector(double x, double y)
    Constructs a Vector pointed in the specified direction.
    Constructs a Vector pointed in the direction specified by a Point.
    Constructs a Vector representing the direction and magnitude between to provided Points.
    Vector(Vector start, Vector end)
    Constructs a Vector representing the difference between two provided Vectors.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    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.
    Creates a new Vector which represents the average of this Vector with another.
    double
    Calculates the cross product of this Vector with another.
    double
    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
    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
    Calculates the similarity of this Vector with another.
    Creates a new Vector which is the difference of this Vector with the provided Vector.
    int
     
    boolean
    Checks whether this vector has a horizontal component.
    boolean
    Checks whether this vector equals (0,0);
    boolean
    Calculates whether this Vector and the provided one are orthogonal to each other.
    boolean
    Calculates whether this Vector and the provided one are parallel to each other.
    boolean
    Checks whether this vector has a vertical component.
    Returns a point representation of this Vector.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • x

      public double x
      the X value
    • y

      public double y
      the 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

      public Vector(PrecisionPoint p)
      Constructs a Vector pointed in the direction specified by a Point.
      Parameters:
      p - the point
    • Vector

      public Vector(PrecisionPoint start, PrecisionPoint end)
      Constructs a Vector representing the direction and magnitude between to provided Points.
      Parameters:
      start - starting point
      end - End Point
    • Vector

      public Vector(Vector start, Vector end)
      Constructs a Vector representing the difference between two provided Vectors.
      Parameters:
      start - The start Ray
      end - The end Ray
  • Method Details

    • getDissimilarity

      public double getDissimilarity(Vector other)
      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

      public boolean isParallelTo(Vector other)
      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

      public double getDotProduct(Vector other)
      Calculates the dot product of this Vector with another.
      Parameters:
      other - the Vector used to calculate the dot product
      Returns:
      The dot product
    • getCrossProduct

      public double getCrossProduct(Vector other)
      Calculates the cross product of this Vector with another.
      Parameters:
      other - the Vector used to calculate the cross product
      Returns:
      The cross product.
    • getAdded

      public Vector getAdded(Vector other)
      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

      public Vector getSubtracted(Vector other)
      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

      public double getAngle(Vector other)
      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

      public Vector getAveraged(Vector other)
      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

      public Vector getMultiplied(double factor)
      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

      public Vector getDivided(double factor)
      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

      public 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

      public double getSimilarity(Vector other)
      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

      public boolean isOrthogonalTo(Vector other)
      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

      public PrecisionPoint toPoint()
      Returns a point representation of this Vector.
      Returns:
      a PrecisionPoint representation
    • toString

      public String toString()
      Overrides:
      toString in class Object
      See Also:
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
      See Also:
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
      See Also: