physics
Class Vect

java.lang.Object
  extended by physics.Vect
All Implemented Interfaces:
java.io.Serializable

public final class Vect
extends java.lang.Object
implements java.io.Serializable

Vect is an immutable abstract data type which models the mathematical notion of a vector or a point in 2-space.

See Also:
Serialized Form

Field Summary
static Vect X_HAT
          A unit vector in the positive x direction
static Vect Y_HAT
          A unit vector in the positive y direction
static Vect ZERO
          A Vect with zero length
 
Constructor Summary
Vect(Angle angle)
           
Vect(Angle angle, double length)
           
Vect(double x, double y)
           
Vect(java.awt.geom.Point2D p)
           
 
Method Summary
 Angle angle()
           
 double distanceSquared(Vect b)
           
 double dot(Vect b)
           
 boolean equals(java.lang.Object o)
           
 boolean equals(Vect v)
           
 int hashCode()
           
 double length()
           
 Vect minus(Vect b)
           
 Vect neg()
           
 Vect plus(Vect b)
           
 Vect projectOn(Vect b)
          Returns the projection of this onto b
 Vect rotateBy(Angle a)
           
 Vect times(double amt)
           
 java.awt.geom.Point2D.Double toPoint2D()
           
 java.lang.String toString()
           
 Vect unitSize()
           
 double x()
           
 double y()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ZERO

public static final Vect ZERO
A Vect with zero length


X_HAT

public static final Vect X_HAT
A unit vector in the positive x direction


Y_HAT

public static final Vect Y_HAT
A unit vector in the positive y direction

Constructor Detail

Vect

public Vect(Angle angle)

Vect

public Vect(Angle angle,
            double length)

Vect

public Vect(double x,
            double y)

Vect

public Vect(java.awt.geom.Point2D p)
Method Detail

angle

public Angle angle()
Returns:
the angle of this in polar coordinates

length

public double length()
Returns:
the length of this

x

public double x()
Returns:
the horizontal coordinate of this in Cartesian coordinates

y

public double y()
Returns:
the vertical coordinate of this in Cartesian coordinates

distanceSquared

public double distanceSquared(Vect b)
Returns:
the square of the distance between the points represented by this and b

plus

public Vect plus(Vect b)
Returns:
the vector sum of this and b

minus

public Vect minus(Vect b)
Returns:
the vector difference of this and b

rotateBy

public Vect rotateBy(Angle a)
Returns:
a vector that is equivalent to this having been rotated around the origin by a.

neg

public Vect neg()
Returns:
a vector that is equivalent to this being rotated by pi radians.

times

public Vect times(double amt)
Returns:
a vector equivalent to this scaled by amt.

projectOn

public Vect projectOn(Vect b)
Returns the projection of this onto b

Returns:
a vector resulting from projecting this onto b. The resulting vector has the same angle as b, but its length is such that this - c is perpendicular to c.

unitSize

public Vect unitSize()
Returns:
a unit vector with the same angle as this

dot

public double dot(Vect b)
Returns:
the dot product of this and b.

toPoint2D

public java.awt.geom.Point2D.Double toPoint2D()
Returns:
a new Point2D object which is located at the same point as this.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(Vect v)

equals

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

hashCode

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