vector
Class Vector3d

java.lang.Object
  extended by vector.Vector3d

public class Vector3d
extends Object

A simple class to represent 3-dimensional vectors. The vector is implemented using an array of double (NOTE: You would not ordinarily document such an implementation detail; I do so here to get you to use an array in your implementation).

Author:
CSE1030Z

Constructor Summary
Vector3d()
          Creates the vector [ 0.0, 0.0, 0.0 ].
Vector3d(double x, double y, double z)
          Creates the vector [ x, y, z ]
 
Method Summary
 Vector3d cross(Vector3d other)
          Computes the cross product with another vector.
 boolean equals(Object obj)
          Compares two vectors for equality.
 double getX()
          Get the x-coordinate of the vector.
 double getY()
          Get the y-coordinate of the vector.
 double getZ()
          Get the z-coordinate of the vector.
 int hashCode()
          Returns a hash code value for this object.
 void setX(double x)
          Set the x-coordinate of the vector.
 void setY(double y)
          Set the y-coordinate of the vector.
 void setZ(double z)
          Set the z-coordinate of the vector.
 String toString()
          Converts this vector to a String of the form [ x y z ] where x, y, and z are the coordinates of the vector.
static Vector3d x()
          Returns the unit vector along the x-axis [ 1.0, 0.0, 0.0 ]
static Vector3d y()
          Returns the unit vector along the y-axis [ 0.0, 1.0, 0.0 ]
static Vector3d z()
          Returns the unit vector along the z-axis [ 0.0, 0.0, 1.0 ]
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Vector3d

public Vector3d()
Creates the vector [ 0.0, 0.0, 0.0 ].


Vector3d

public Vector3d(double x,
                double y,
                double z)
Creates the vector [ x, y, z ]

Parameters:
x - The x-coordinate of the vector.
y - The y-coordinate of the vector.
z - The z-coordinate of the vector.
Method Detail

x

public static Vector3d x()
Returns the unit vector along the x-axis [ 1.0, 0.0, 0.0 ]

Returns:
The vector [ 1.0, 0.0, 0.0 ]

y

public static Vector3d y()
Returns the unit vector along the y-axis [ 0.0, 1.0, 0.0 ]

Returns:
The vector [ 0.0, 1.0, 0.0 ]

z

public static Vector3d z()
Returns the unit vector along the z-axis [ 0.0, 0.0, 1.0 ]

Returns:
The vector [ 0.0, 0.0, 1.0 ]

getX

public double getX()
Get the x-coordinate of the vector.

Returns:
The x-coordinate of the vector.

getY

public double getY()
Get the y-coordinate of the vector.

Returns:
The y-coordinate of the vector.

getZ

public double getZ()
Get the z-coordinate of the vector.

Returns:
The z-coordinate of the vector.

setX

public void setX(double x)
Set the x-coordinate of the vector.

Parameters:
x - The value to set the x-coordinate of the vector.

setY

public void setY(double y)
Set the y-coordinate of the vector.

Parameters:
y - The value to set the y-coordinate of the vector.

setZ

public void setZ(double z)
Set the z-coordinate of the vector.

Parameters:
z - The value to set the z-coordinate of the vector.

cross

public Vector3d cross(Vector3d other)
Computes the cross product with another vector.

Parameters:
other - The vector to take the cross product with.
Returns:
The cross product this x other.

equals

public boolean equals(Object obj)
Compares two vectors for equality. The result is true if and only if the argument is not null and two vectors have the same coordinates.

Overrides:
equals in class Object
Parameters:
obj - The object to compare with.
Returns:
true if the objects are the same; false otherwise.

hashCode

public int hashCode()
Returns a hash code value for this object.

Overrides:
hashCode in class Object
Returns:
A hash code value for this object.

toString

public String toString()
Converts this vector to a String of the form [ x y z ] where x, y, and z are the coordinates of the vector.

Overrides:
toString in class Object
Returns:
A string representation of this vector.