Eclipse Draw2d
3.3

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()
          Constructs a Vector with no direction and magnitude.
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 vector)
          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.
 double getDotProduct(Vector other)
          Calculates the dot product of this Vector with another.
 double getLength()
          Returns the length of this Vector.
 Vector getOrthogonalComplement()
          Returns the orthogonal complement of this Vector, which is defined to be (-y, x).
 Vector getScaled(double scale)
          Creates a new Vector which represents this Vector scaled by the amount provided.
 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 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.
 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()
Constructs a Vector with no direction and magnitude.


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
See Also:
getSimilarity(Vector)

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 vector)
Creates a new Vector which represents the average of this Vector with another.

Parameters:
vector - Vector to calculate the average.
Returns:
a new Vector

getScaled

public Vector getScaled(double scale)
Creates a new Vector which represents this Vector scaled by the amount provided.

Parameters:
scale - 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

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.3

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