Class SpaceVector

java.lang.Object
  |
  +--SpaceVector

public class SpaceVector
extends java.lang.Object
implements java.io.Serializable

Implementation of representation of a vector in space; that is, a component vector in the three dimensional rectangular coordinate system. This class provides the basic operations of constant vectors for the simplification of all problems to which it applies.

See Also:
Serialized Form

Constructor Summary
SpaceVector(double x, double y, double z)
          Creates a new SpaceVector from the specified doubles.
SpaceVector(float x, float y, float z)
          Creates a new SpaceVector.
 
Method Summary
 void add(SpaceVector sv)
          Sets the value of this SpaceVector to the sum of this + the argument sv.
 float angleBetween(SpaceVector sv)
          Returns the angle between this SpaceVector and the argument SpaceVector sv.
 java.lang.Object clone()
          Returns an exact clone of this SpaceVector.
 float cosBetween(SpaceVector sv)
          Returns the value of cos(theta) where cos(theta) = (u · v)/(||u|| ||v||).
 float dot(SpaceVector sv)
          Returns the dot product of this SpaceVector and the specified SpaceVectorsv.
static boolean equal(double d1, double d2)
          Determines whether two doubles are close enough together to be considered equal.
static boolean equal(float f1, float f2)
          Determines whether two floats are close enough together to be considered equal.
 boolean equals(float X, float Y, float Z)
          Determines if this vector is equal to the corresponding vector defined by the x, y, z coordinates.
 boolean equals(java.lang.Object o)
          Determines whether the Object parameter is equal to this SpaceVector or not.
 boolean equals(SpaceVector sv)
          Determines whether the vector is equivalent to the specified SpaceVector argument.
 SpaceVector getCrossProduct(SpaceVector sv)
          Returns the SpaceVector representation of the cross product given by this SpaceVector × the argument SpaceVector.
 SpaceVector getMultiple(float c)
          Returns a new SpaceVector which has been scaled by the float c.
 SpaceVector getNegation()
          Returns a negated version of this SpaceVector.
 SpaceVector getOrthogonalComponentOf(SpaceVector sv)
          Returns the vector component of this orthogonal to the argument sv.
 SpaceVector getProjectionOnto(SpaceVector sv)
          Returns the projection of this SpaceVector onto the SpaceVector sv.
 SpaceVector getSum(SpaceVector sv)
          Returns a new SpaceVector representing the sum of this SpaceVector with the argument SpaceVector sv.
 SpaceVector getUnitVector()
          Returns the unit vector version of this SpaceVector.
 float getX()
          Returns the x-component of the SpaceVector.
 float getY()
          Returns the y-component of the SpaceVector.
 float getZ()
          Returns the z-component of the SpaceVector.
 int hashCode()
          Returns a hashcode for this SpaceVector object.
 boolean isOrthogonal(SpaceVector sv)
          Determines if this SpaceVector is orthogonal to the specified SpaceVector sv.
 boolean isParallel(SpaceVector sv)
          Determines if the specified SpaceVector sv is parallel with this SpaceVector.
 boolean isUnitVector()
          Duhhhhh...
 boolean isZeroVector()
          Determines whether this is the zero vector 0.
 float magnitude()
          Returns the magnitude ||this|| of this SpaceVector.
static double magnitude(double x, double y, double z)
          Returns the magnitude of the given x, y, and z values of the specified vector in space <x, y, z>.
static float magnitude(float x, float y, float z)
          Returns the magnitude of the given x, y, and z values of the specified vector in space <x, y, z>.
 void multiply(double c)
          Scales this SpaceVector to the scalar double c.
 void multiply(float c)
          Scales this SpaceVector to the scalar float c.
 void negate()
          Sets this SpaceVector's value to the opposite direction.
 void paintArrow(float initialX, float initialY, float initialZ, int centX, int centY, int screenDistance, float arrowSize, java.awt.Color color, java.awt.Graphics g)
           
 void paintLine(float initialX, float initialY, float initialZ, int centX, int centY, java.awt.Color color, java.awt.Graphics g)
           
 void projectOnto(SpaceVector sv)
          Sets this SpaceVector equal to the projection of itself onto the SpaceVector argument sv denoted by projthissv.
 void rotateAbout(double arx, double ary, double arz, double theta)
          Rotates this SpaceVector theta radians about the line <arx, ary, arz>.
 void rotateAbout(float arx, float ary, float arz, float theta)
          Rotates this SpaceVector theta radians about the line <arx, ary, arz>.
 void rotateAbout(SpaceVector sv, double theta)
          Rotates this SpaceVector theta radians about the line denoted by the SpaceVector sv.
 void rotateAbout(SpaceVector sv, float theta)
          Rotates this SpaceVector theta radians about the line denoted by the SpaceVector sv.
 void rotateX(float theta)
          Rotates this SpaceVector theta radians about the x-axis.
 void rotateY(float theta)
          Rotates this SpaceVector theta radians about the y-axis.
 void rotateZ(float theta)
          Rotates this SpaceVector theta radians about the z-axis.
 void setX(double x)
          Sets the x-component to the specified value.
 void setX(float x)
          Sets the x-component to the specified value.
 void setY(double y)
          Sets the y-component to the specified value.
 void setY(float y)
          Sets the y-component to the specified value.
 void setZ(double z)
          Sets the z-component to the specified value.
 void setZ(float z)
          Sets the z-component to the specified value.
 void subtract(SpaceVector sv)
          Same as the add method except sv is negative.
 void toCrossProduct(SpaceVector sv)
          Sets this SpaceVector equal to the cross product given by this SpaceVector × the argument SpaceVector.
 void toOrthogonalComponentOf(SpaceVector sv)
          Sets this SpaceVector to be the vector component of this orthogonal to the argument sv.
 java.lang.String toString()
          Returns a String representation of this SpaceVector object.
 void toUnitVector()
          Sets the value of this SpaceVector to its equivalent unit vector.
 float xCos()
          Returns the direction cosine between this SpaceVector and the x-axis.
 float yCos()
          Returns the direction cosine between this SpaceVector and the y-axis.
 float zCos()
          Returns the direction cosine between this SpaceVector and the z-axis.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SpaceVector

public SpaceVector(float x,
                   float y,
                   float z)
Creates a new SpaceVector.

SpaceVector

public SpaceVector(double x,
                   double y,
                   double z)
Creates a new SpaceVector from the specified doubles. The coordinates will be transformes to floats. All operations are done internally on four byte floats.
Method Detail

getX

public final float getX()
Returns the x-component of the SpaceVector.

getY

public final float getY()
Returns the y-component of the SpaceVector.

getZ

public final float getZ()
Returns the z-component of the SpaceVector.

setX

public final void setX(float x)
Sets the x-component to the specified value.

setY

public final void setY(float y)
Sets the y-component to the specified value.

setZ

public final void setZ(float z)
Sets the z-component to the specified value.

setX

public final void setX(double x)
Sets the x-component to the specified value. The double is internally converted to a float before any assignments are made.

setY

public final void setY(double y)
Sets the y-component to the specified value. The double is internally converted to a float before any assignments are made.

setZ

public final void setZ(double z)
Sets the z-component to the specified value. The double is internally converted to a float before any assignments are made.

add

public final void add(SpaceVector sv)
Sets the value of this SpaceVector to the sum of this + the argument sv.
See Also:
getSum(SpaceVector sv)

subtract

public final void subtract(SpaceVector sv)
Same as the add method except sv is negative.

getSum

public final SpaceVector getSum(SpaceVector sv)
Returns a new SpaceVector representing the sum of this SpaceVector with the argument SpaceVector sv. Does not change the value of this SpaceVector.
See Also:
add(SpaceVector sv)

multiply

public final void multiply(float c)
Scales this SpaceVector to the scalar float c.

multiply

public final void multiply(double c)
Scales this SpaceVector to the scalar double c.

getMultiple

public final SpaceVector getMultiple(float c)
Returns a new SpaceVector which has been scaled by the float c. Does not change the value of this SpaceVector.
Returns:
a scaled version of this SpaceVector.

negate

public final void negate()
Sets this SpaceVector's value to the opposite direction.
See Also:
getNegation()

getNegation

public final SpaceVector getNegation()
Returns a negated version of this SpaceVector. Does not change the value of this SpaceVector.
See Also:
negate()

getUnitVector

public final SpaceVector getUnitVector()
Returns the unit vector version of this SpaceVector. Does not change the value of this SpaceVector.
See Also:
toUnitVector()

toUnitVector

public final void toUnitVector()
Sets the value of this SpaceVector to its equivalent unit vector.
See Also:
getUnitVector()

isUnitVector

public final boolean isUnitVector()
Duhhhhh... if being called frequently, then very inefficient.

magnitude

public final float magnitude()
Returns the magnitude ||this|| of this SpaceVector. Every time this method is called, the magnitude is recalculated by
(float)Math.sqrt( x*x + y*y + z*z );

magnitude

public static final float magnitude(float x,
                                    float y,
                                    float z)
Returns the magnitude of the given x, y, and z values of the specified vector in space <x, y, z>.
Parameters:
x - the x component of the specified vector.
y - the y component of the specified vector.
z - the z component of the specified vector.

magnitude

public static final double magnitude(double x,
                                     double y,
                                     double z)
Returns the magnitude of the given x, y, and z values of the specified vector in space <x, y, z>.
Parameters:
x - the x component of the specified vector.
y - the y component of the specified vector.
z - the z component of the specified vector.

isParallel

public final boolean isParallel(SpaceVector sv)
Determines if the specified SpaceVector sv is parallel with this SpaceVector.
Returns:
true if this = csv. otherwize false.

isZeroVector

public final boolean isZeroVector()
Determines whether this is the zero vector 0.

dot

public final float dot(SpaceVector sv)
Returns the dot product of this SpaceVector and the specified SpaceVectorsv.

Definition of Dot Product
The dot product of u = <u1, u2, u3 > and v = < v1, v2, v3 > is
u · v = u1v1 + u2v2 + u3v3.

Properties of the Dot Product

Returns:
this · sv

angleBetween

public final float angleBetween(SpaceVector sv)
Returns the angle between this SpaceVector and the argument SpaceVector sv. The value is found from theta = acos( (u · v)/(||u|| ||v||) ). Returns the value of theta.

cosBetween

public final float cosBetween(SpaceVector sv)
Returns the value of cos(theta) where cos(theta) = (u · v)/(||u|| ||v||).

isOrthogonal

public final boolean isOrthogonal(SpaceVector sv)
Determines if this SpaceVector is orthogonal to the specified SpaceVector sv. In other words, returns true iff this · sv = 0, otherwize false.

xCos

public final float xCos()
Returns the direction cosine between this SpaceVector and the x-axis.

yCos

public final float yCos()
Returns the direction cosine between this SpaceVector and the y-axis.

zCos

public final float zCos()
Returns the direction cosine between this SpaceVector and the z-axis.

rotateX

public final void rotateX(float theta)
Rotates this SpaceVector theta radians about the x-axis.

rotateY

public final void rotateY(float theta)
Rotates this SpaceVector theta radians about the y-axis.

rotateZ

public final void rotateZ(float theta)
Rotates this SpaceVector theta radians about the z-axis.

rotateAbout

public final void rotateAbout(float arx,
                              float ary,
                              float arz,
                              float theta)
Rotates this SpaceVector theta radians about the line <arx, ary, arz>.

rotateAbout

public final void rotateAbout(double arx,
                              double ary,
                              double arz,
                              double theta)
Rotates this SpaceVector theta radians about the line <arx, ary, arz>.

rotateAbout

public final void rotateAbout(SpaceVector sv,
                              float theta)
Rotates this SpaceVector theta radians about the line denoted by the SpaceVector sv.

rotateAbout

public final void rotateAbout(SpaceVector sv,
                              double theta)
Rotates this SpaceVector theta radians about the line denoted by the SpaceVector sv.

projectOnto

public final void projectOnto(SpaceVector sv)
Sets this SpaceVector equal to the projection of itself onto the SpaceVector argument sv denoted by projthissv.
See Also:
getProjectionOnto(SpaceVector sv)

getProjectionOnto

public final SpaceVector getProjectionOnto(SpaceVector sv)
Returns the projection of this SpaceVector onto the SpaceVector sv.
See Also:
projectOnto(SpaceVector sv)

toOrthogonalComponentOf

public final void toOrthogonalComponentOf(SpaceVector sv)
Sets this SpaceVector to be the vector component of this orthogonal to the argument sv. Equal to this - projsvthis.
Parameters:
sv - the SpaceVector which this SpaceVector is projected onto.
See Also:
getOrthogonalComponentOf(SpaceVector sv)

getOrthogonalComponentOf

public final SpaceVector getOrthogonalComponentOf(SpaceVector sv)
Returns the vector component of this orthogonal to the argument sv. Equal to this - projsvthis.
Parameters:
sv - the SpaceVector which this SpaceVector is projected onto.
Returns:
a SpaceVector representing the vector component of this SpaceVector to sv.
See Also:
toOrthogonalComponentOf(SpaceVector sv)

getCrossProduct

public final SpaceVector getCrossProduct(SpaceVector sv)
Returns the SpaceVector representation of the cross product given by this SpaceVector × the argument SpaceVector.

Definition of Cross Product of Two Vectors in Space
Let u = u1i + u2j + u3k and v = v1i + v2j + v3k. The cross product of u and v is the vector
u × v = ( u2v3 - u3v2)i - (u1v3 - u3v1)j + (u1v2 - u2v1)k.

Algebraic Properties of the Cross Product

Geometric Properties of the Cross Product

Parameters:
sv - The SpaceVector being crossed with this SpaceVector.
Returns:
a new SpaceVector of the cross product this × sv.
See Also:
toCrossProduct(SpaceVector sv)

toCrossProduct

public final void toCrossProduct(SpaceVector sv)
Sets this SpaceVector equal to the cross product given by this SpaceVector × the argument SpaceVector. A table of algebraic and geometric properties are given in the documentation on the getCrossProduct(SpaceVector sv) method.
Parameters:
the - SpaceVector from which the cross product is taken in conjunction with this SpaceVector.
See Also:
getCrossProduct(SpaceVector sv)

toString

public java.lang.String toString()
Returns a String representation of this SpaceVector object. The value represented by this SpaceVector is converted to a String in the standard component vector format of < x, y, z > .
Overrides:
toString in class java.lang.Object
Returns:
a String representation of this object.

hashCode

public int hashCode()
Returns a hashcode for this SpaceVector object.
Overrides:
hashCode in class java.lang.Object
Returns:
the value of hashCode() generated by the String returned from toString() of this SpaceVector.
See Also:
toString()

equals

public boolean equals(java.lang.Object o)
Determines whether the Object parameter is equal to this SpaceVector or not.
Overrides:
equals in class java.lang.Object

equals

public boolean equals(SpaceVector sv)
Determines whether the vector is equivalent to the specified SpaceVector argument.

equals

public final boolean equals(float X,
                            float Y,
                            float Z)
Determines if this vector is equal to the corresponding vector defined by the x, y, z coordinates.

clone

public java.lang.Object clone()
Returns an exact clone of this SpaceVector.
Overrides:
clone in class java.lang.Object

equal

public static final boolean equal(float f1,
                                  float f2)
Determines whether two floats are close enough together to be considered equal.

equal

public static final boolean equal(double d1,
                                  double d2)
Determines whether two doubles are close enough together to be considered equal.

paintLine

public final void paintLine(float initialX,
                            float initialY,
                            float initialZ,
                            int centX,
                            int centY,
                            java.awt.Color color,
                            java.awt.Graphics g)

paintArrow

public final void paintArrow(float initialX,
                             float initialY,
                             float initialZ,
                             int centX,
                             int centY,
                             int screenDistance,
                             float arrowSize,
                             java.awt.Color color,
                             java.awt.Graphics g)