Eclipse Draw2d
3.8.0.201206011245

org.eclipse.draw2d.geometry
Class Vector

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

public class Vector
extends Object

Represents a vector within 2-dimensional Euclidean space.

Since:
3.6

Field Summary
 double x
          the X value
 double y
          the Y value
 
Constructor Summary
Vector(double x, double y)
          Constructs a Vector pointed in the specified direction.
Vector(PrecisionPoint p)
          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.
Vector(Vector start, Vector end)
          Constructs a Vector representing the difference between two provided Vectors.
 
Method Summary
 boolean equals(Object obj)
           
 Vector getAdded(Vector other)
          Creates a new Vector which is the sum of this Vector with another.
 double getAngle(Vector other)
          Returns the angle (in degrees) between this Vector and the provided Vector.
 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.
 Vector 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 getLength()
          Returns the length of this Vector.
 Vector getMultiplied(double factor)
          Creates a new Vector which represents this Vector multiplied by the provided scalar factor.
 Vector getOrthogonalComplement()
          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.
 Vector getSubtracted(Vector other)
          Creates a new Vector which is the difference of this Vector with the provided Vector.
 int hashCode()
           
 boolean isHorizontal()
          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 isVertical()
          Checks whether this vector has a vertical component.
 PrecisionPoint toPoint()
          Returns a point representation of this Vector.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public double x
the X value


y

public double y
the Y value

Constructor Detail

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 Detail

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:
getDissimilarity(Vector)

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:
Object.toString()

equals

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

hashCode

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

Eclipse Draw2d
3.8.0.201206011245

Copyright (c) IBM Corp. and others 2000, 2011. All Rights Reserved.