physics3d
Class Vect3

java.lang.Object
  extended by physics3d.Vect3

public class Vect3
extends Object

Vect3 represents a vector in 3 space

Specification Fields

Field Summary
static Vect3 X_HAT
          A unit vector in the positive x direction
static Vect3 Y_HAT
          A unit vector in the positive y direction
static Vect3 Z_HAT
          A unit vector in the positive z direction
static Vect3 ZERO
          A Vect3 with zero length
 
Constructor Summary
Vect3(Angle theta, Angle phi)
           
Vect3(double rho, Angle theta, Angle phi)
           
Vect3(double x, double y, double z)
           
 
Method Summary
 Angle angleBetween(Vect3 b)
           
 Vect3 cross(Vect3 b)
           
 double distanceSquared(Vect3 b)
           
 double dot(Vect3 b)
           
 boolean equals(Object o)
           
 boolean equals(Vect3 v)
           
 int hashCode()
           
static boolean isAbout(double d1, double d2)
           
 boolean isAbout(Vect3 v1)
           
 Vect3 minus(Vect3 b)
           
 Vect3 neg()
           
 Angle phi()
           
 Vect3 plus(Vect3 b)
           
 Vect3 projectOnToB(Vect3 b)
          Returns the projection of this onto b
 double rho()
           
 Vect3 rotateAroundVect(Vect3 axis, Angle ccwRotAngle)
           
static double roundToNearest100(double d)
           
 Angle theta()
           
 Vect3 times(double amt)
           
 String toString()
           
 Vect3 unitSize()
           
 double x()
           
 double y()
           
 double z()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ZERO

public static final Vect3 ZERO
A Vect3 with zero length


X_HAT

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


Y_HAT

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


Z_HAT

public static final Vect3 Z_HAT
A unit vector in the positive z direction

Constructor Detail

Vect3

public Vect3(Angle theta,
             Angle phi)
Requires:
theta, phi are not null
Effects:
constructs a new unit vector in the direction of theta, phi.

Vect3

public Vect3(double rho,
             Angle theta,
             Angle phi)
Requires:
theta, phi are not null
Effects:
constructs a new vector in the direction of theta, phi with length rho, where (rho, theta, phi) is the standard spherical representation of a point in 3 space.

Vect3

public Vect3(double x,
             double y,
             double z)
Effects:
constructs a new vector in Cartesian space with coordinates (x,y,z).
Method Detail

rho

public double rho()
Returns:
the length of this

theta

public Angle theta()
Returns:
the angle of this to the z axis

phi

public Angle phi()
Returns:
the angle of this to the x axis, measured from the XY plane.

x

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

y

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

z

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

distanceSquared

public double distanceSquared(Vect3 b)
Returns:
the square of the distance between the points represented by this and b
Requires:
b is not null

angleBetween

public Angle angleBetween(Vect3 b)
Returns:
the angle between this and b

plus

public Vect3 plus(Vect3 b)
Returns:
the vector sum of this and b
Requires:
b is not null

minus

public Vect3 minus(Vect3 b)
Returns:
the vector difference of this and b
Requires:
b is not null

neg

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

times

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

projectOnToB

public Vect3 projectOnToB(Vect3 b)
Returns the projection of this onto b

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

cross

public Vect3 cross(Vect3 b)
Returns:
the vector c = (this.y()*b.z() - b.y()*this.z()) i, (this.z()*b.x() - b.z()*this.x()) j, (this.x()*b.y() - b.x()*this.y()) k c satisfies: c.rho() = this.rho()*b.rho()*this.angleBetween(b).sin()
Requires:
b is not null

unitSize

public Vect3 unitSize()
Returns:
a unit vector with the direction as this
Requires:
this.rho() >= 0

rotateAroundVect

public Vect3 rotateAroundVect(Vect3 axis,
                              Angle ccwRotAngle)
Returns:
a vector which is this rotated counter clockwise by an angle ccwRotAngle about the axis of rotation axis.
Requires:
axis is not null && axis.rho() > 0 && ccwRotAngle is not null

dot

public double dot(Vect3 b)
Returns:
the dot product of this and b.
Requires:
b is not null

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Vect3 v)

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

isAbout

public boolean isAbout(Vect3 v1)
Parameters:
d1 -
d2 -
Returns:
true if |d1-d2| < GameConstants.Tolerance false otherwise
Requires:
v1 is not null

isAbout

public static boolean isAbout(double d1,
                              double d2)
Parameters:
d1 -
d2 -
Returns:
true if |d1-d2| < GameConstants.Tolerance false otherwise

roundToNearest100

public static double roundToNearest100(double d)
Returns:
d rounded to nearest hundreth