org.naokishibata.math
Class Vector2D

java.lang.Object
  extended by org.naokishibata.math.Vector2D
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable

public class Vector2D
extends java.lang.Object
implements java.io.Serializable, java.lang.Comparable

Vector2D is an immutable class representing a 2-dimensional vector.

See Also:
Serialized Form

Field Summary
 double x
          The first coordinate.
 double y
          The first coordinate.
 
Constructor Summary
Vector2D(double x0, double y0)
          Constructs a new Vector2D instance which represents (x0, y0) vector.
 
Method Summary
static Vector2D add(Vector2D v, Vector2D u)
          Returns the addition of vectors v and u.
static Vector2D add(Vector2D v, Vector2D u, Vector2D w)
          Returns the addition of vectors v, u and w.
static Vector2D add(Vector2D v, Vector2D u, Vector2D w, Vector2D x)
          Returns the addition of vectors v, u, w and x.
static double angle(Vector2D v, Vector2D w)
          Returns the angle between v and w.
 int compareTo(java.lang.Object o)
           
 double cross(Vector2D v)
           
static double crossProduct(Vector2D v, Vector2D u)
          Returns the cross product of vectors v and u.
static double distance(Vector2D v, Vector2D w)
          Returns the distance between v and w.
static double distanceSquared(Vector2D v, Vector2D w)
          Returns the squared distance between v and w.
 Vector2D dot(double d)
           
 double dot(Vector2D v)
          Returns the cross product of this and v
static double dotProduct(Vector2D v, Vector2D u)
          Returns the dot product of vectors v and u.
 boolean epsilonEquals(Vector2D v)
           
 boolean epsilonEquals(Vector2D v, double eps)
           
static boolean epsilonEquals(Vector2D v, Vector2D u)
           
static boolean epsilonEquals(Vector2D v, Vector2D u, double eps)
           
 boolean equals(java.lang.Object o)
           
 boolean equals(Vector2D v)
           
static boolean equals(Vector2D v, Vector2D u)
           
 int hashCode()
           
 double length()
          Returns the length of this vector.
static double length(Vector2D v)
          Returns the length of v.
static double lengthSquared(Vector2D v)
          Returns the squared length of v.
static Vector2D midpoint(Vector2D v, Vector2D w)
          Returns the midpoint between v and w.
 Vector2D minus(Vector2D v)
          Returns this - v
 Vector2D normalize()
           
static Vector2D normalize(Vector2D v)
          Returns the normalized vector of v.
 Vector2D normalized()
           
 Vector2D orthogonal()
           
 Vector2D plus(Vector2D v)
          Returns this + v
static Vector2D scale(double s, Vector2D v)
          Returns vector v scaled by s
static Vector2D scale(Vector2D v, double s)
          Returns vector v scaled by s
static Vector2D sub(Vector2D v, Vector2D u)
          Returns v - u.
 java.lang.String toString()
          Returns the string representation of the vector.
 double x()
          Returns the first coordinate.
 double y()
          Returns the second coordinate.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public final double x
The first coordinate.


y

public final double y
The first coordinate.

Constructor Detail

Vector2D

public Vector2D(double x0,
                double y0)
Constructs a new Vector2D instance which represents (x0, y0) vector.

Method Detail

x

public double x()
Returns the first coordinate.


y

public double y()
Returns the second coordinate.


toString

public java.lang.String toString()
Returns the string representation of the vector.

Overrides:
toString in class java.lang.Object

add

public static Vector2D add(Vector2D v,
                           Vector2D u)
Returns the addition of vectors v and u.


add

public static Vector2D add(Vector2D v,
                           Vector2D u,
                           Vector2D w)
Returns the addition of vectors v, u and w.


add

public static Vector2D add(Vector2D v,
                           Vector2D u,
                           Vector2D w,
                           Vector2D x)
Returns the addition of vectors v, u, w and x.


sub

public static Vector2D sub(Vector2D v,
                           Vector2D u)
Returns v - u.


dotProduct

public static double dotProduct(Vector2D v,
                                Vector2D u)
Returns the dot product of vectors v and u.


crossProduct

public static double crossProduct(Vector2D v,
                                  Vector2D u)
Returns the cross product of vectors v and u.


scale

public static Vector2D scale(double s,
                             Vector2D v)
Returns vector v scaled by s


scale

public static Vector2D scale(Vector2D v,
                             double s)
Returns vector v scaled by s


normalize

public static Vector2D normalize(Vector2D v)
Returns the normalized vector of v.


length

public static double length(Vector2D v)
Returns the length of v.


lengthSquared

public static double lengthSquared(Vector2D v)
Returns the squared length of v.


distance

public static double distance(Vector2D v,
                              Vector2D w)
Returns the distance between v and w.


distanceSquared

public static double distanceSquared(Vector2D v,
                                     Vector2D w)
Returns the squared distance between v and w.


midpoint

public static Vector2D midpoint(Vector2D v,
                                Vector2D w)
Returns the midpoint between v and w.


angle

public static double angle(Vector2D v,
                           Vector2D w)
Returns the angle between v and w.


epsilonEquals

public static boolean epsilonEquals(Vector2D v,
                                    Vector2D u,
                                    double eps)

epsilonEquals

public static boolean epsilonEquals(Vector2D v,
                                    Vector2D u)

equals

public static boolean equals(Vector2D v,
                             Vector2D u)

length

public double length()
Returns the length of this vector.


normalize

public Vector2D normalize()

epsilonEquals

public boolean epsilonEquals(Vector2D v,
                             double eps)

epsilonEquals

public boolean epsilonEquals(Vector2D v)

plus

public Vector2D plus(Vector2D v)
Returns this + v


minus

public Vector2D minus(Vector2D v)
Returns this - v


dot

public double dot(Vector2D v)
Returns the cross product of this and v


dot

public Vector2D dot(double d)

cross

public double cross(Vector2D v)

orthogonal

public Vector2D orthogonal()

normalized

public Vector2D normalized()

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

compareTo

public int compareTo(java.lang.Object o)
Specified by:
compareTo in interface java.lang.Comparable

equals

public boolean equals(Vector2D v)

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object