keps.math
Class Vector3

java.lang.Object
  extended by keps.math.Tuple3
      extended by keps.math.Vector3

public class Vector3
extends Tuple3

GENERAL CONTRACT FOR ALL MATH CLASSES. -- The destination of every method is assumed to be the object the method was called on. For example: c.add(a,b) means c = a + b. -- Whenever one operand of a binary operand is missing, it is assumed to be the object the method was called upon. For example: c.add(a) means c = c + a. The Vector3 class represents a 3 dimension vector of doubles.

Author:
ags Aug 18, 2005 Tuple3.java Copyright 2005 Program of Computer Graphics, Cornell University

Field Summary
 
Fields inherited from class keps.math.Tuple3
x, y, z
 
Constructor Summary
Vector3()
          Default constructor.
Vector3(double newX, double newY, double newZ)
          The explicit constructor.
Vector3(Tuple3 newTuple)
          Copy constructor.
 
Method Summary
 void add(Vector3 vector)
          Add a Vector3 to this Vector3
 void add(Vector3 v1, Vector3 v2)
          Add the values of Vector3 v1 and Vector3 v2 and store the sum in this Vector3.
 void cross(Vector3 op1, Vector3 op2)
          Sets this vector to the cross product of op1 and op2
 double dot(Vector3 rhs)
          Returns the dot product of this Vector3 object and the parameter Vector3.
 double length()
          Returns the length of this vector.
 double lengthsquared()
          Returns the length squared of this vector.
 void normalize()
          This method will normalize this Vector3 so that its length is 1.0.
 void scaleAdd(double scale, Tuple3 vector)
          Add a scalar multiple of a Vector3 to this Vector3
 void sub(Point3 p1, Point3 p2)
          Subtract one Point3 from another Point3 and set as this Vector
 void sub(Vector3 vector)
          Substract a Vector3 from this Vector3
 
Methods inherited from class keps.math.Tuple3
scale, set, set, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Vector3

public Vector3()
Default constructor. Uses explicit constructor to create a zero vector.


Vector3

public Vector3(Tuple3 newTuple)
Copy constructor. This constructor simply calls the explicit constructor with the necessary fields from the input as parameters.

Parameters:
newTuple - The vector to copy.

Vector3

public Vector3(double newX,
               double newY,
               double newZ)
The explicit constructor. This is the only constructor with any real code in it. Values should be set here, and any variables that need to be calculated should be done here.

Parameters:
newX - The x value of the new vector.
newY - The y value of the new vector.
newZ - The z value of the new vector.
Method Detail

cross

public void cross(Vector3 op1,
                  Vector3 op2)
Sets this vector to the cross product of op1 and op2

Parameters:
op1 -
op2 -

dot

public double dot(Vector3 rhs)
Returns the dot product of this Vector3 object and the parameter Vector3.

Parameters:
rhs - The right hand operand.
Returns:
The dot product of this Vector3 object and the parameter Vector3.

length

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

Returns:
The length of this vector.

lengthsquared

public double lengthsquared()
Returns the length squared of this vector. Very useful if only comparison of lengths is needed since it saves the square root.

Returns:
the length squared of this vector3

normalize

public void normalize()
This method will normalize this Vector3 so that its length is 1.0. If the length of the Vector3 is 0, no action is taken.


add

public void add(Vector3 vector)
Add a Vector3 to this Vector3

Parameters:
vector - the Vector3 to add

add

public void add(Vector3 v1,
                Vector3 v2)
Add the values of Vector3 v1 and Vector3 v2 and store the sum in this Vector3.

Parameters:
v1 - the first operand
v2 - the second operand

sub

public void sub(Vector3 vector)
Substract a Vector3 from this Vector3

Parameters:
vector - the Tuple3 to subtract

sub

public void sub(Point3 p1,
                Point3 p2)
Subtract one Point3 from another Point3 and set as this Vector

Parameters:
p1 - the first operand
p2 - the second operand

scaleAdd

public void scaleAdd(double scale,
                     Tuple3 vector)
Add a scalar multiple of a Vector3 to this Vector3

Parameters:
scale - the scale factor
vector - the vector to scale add