|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.proteinshader.math.Vec3d
public class Vec3d
This class is used to create a vector with 3 elements of type double.
The Vec3f class is nearly identical, except that it happens to use
floats rather than doubles.
Public instances variables are generally discouraged in Java, but
can be justified here. The x, y, and z attributes will be used in
numerous calculations, and v.x, v.y, and v.z are simply much shorter
than v.getX(), v.getY(), and v.getZ(). Also, any value is allowed
for an attribute of a Vec3d, so there doesn't seem to be any real
advantage to making the xyz-coordinates of this data structure
private.
Several of the methods in this class come in two versions: one that
modifies the calling vector and one that returns a new vector instead
of modifying the calling vector. For example, the add(Vec3d) method
adds the respective xyz-values of the calling and argument vectors
in order to create a new vector, and the original vectors are not
modified. The addToMe(Vec3d) void method, however, modifies the
xyz-values of the calling vector by adding to them the xyz-values of
the vector given as an argument.
Field Summary | |
---|---|
static String |
DECIMAL_FORMAT
As a convienence for debugging, the toString() method will return a representation of a vector in the general form "(x, y, z)", where the number of decimal places for each value will be determined this decimal format String, which is "0.000". |
double |
x
The public x-coordinate of this three element vector. |
double |
y
The public y-coordinate of this three element vector. |
double |
z
The public z-coordinate of this three element vector. |
Constructor Summary | |
---|---|
Vec3d()
Constructs a vector of 3 elements {x, y, z} filled with zeros. |
|
Vec3d(double x,
double y,
double z)
Constructs a vector with three public attributes: x, y, and z. |
Method Summary | |
---|---|
Vec3d |
add(Vec3d vec)
Creates a new vector by adding the vector given as an argument to the calling vector (the existing vectors are NOT modified). |
void |
addToMe(Vec3d vec)
Modifies the calling vector by adding the xyz-values of the vector given as an argument to the xyz-values of the calling vector. |
Vec3d |
clone()
Returns a clone of the calling vector. |
Vec3d |
cross(Vec3d vec)
Creates a new vector by taking the cross product of the calling vector and the vector given as an argument. |
void |
crossMe(Vec3d vec)
Modifies the calling vector by calculating the cross product of the calling vector and the vector given as an argument and storing the result in the calling vector. |
double |
dot(Vec3d vec)
Returns the dot product of the calling vector and the vector given as an argument. |
double |
magnitude()
Calculates the magnitude of the calling vector. |
Vec3d |
minus(Vec3d vec)
Creates a new vector by subtracting the vector given as an argument from the calling vector (the existing vectors are NOT modified). |
void |
minusFromMe(Vec3d vec)
The x, y, and z values of the vector given as an argument are subtracted from the x, y, and z values of the calling vector. |
Vec3d |
negate()
Creates a new vector equal in magnitude but opposite in direction to the calling vector (the calling vector is NOT modified). |
void |
negateMe()
The direction of the calling vector is reversed by setting x to -x, y to -y, and z to -z. |
Vec3d |
normalize()
Creates a new vector that has the same direction as the calling vector, but is of unit length (the calling vector is NOT modified). |
void |
normalizeMe()
Normalizes the calling vector by determining its length (magnitude) and then dividing x, y, and z by the length. |
Vec3d |
scale(double magnitude)
Creates a new vector by scaling the calling vector by the magnitude given as an argument (the calling vector is NOT modified). |
void |
scaleMe(double magnitude)
Scales the calling vector by the value given as an argument. |
void |
setXYZ(double x,
double y,
double z)
Sets the xyz-values of the vector. |
void |
setXYZ(Vec3d vec)
Sets the xyz-values of the vector to the xyz-values of the vector given as an argument. |
String |
toString()
As a convenience for debugging, the toString() method returns the xyz-coordinates of the vector in the form "(x, y, z)". |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String DECIMAL_FORMAT
public double x
public double y
public double z
Constructor Detail |
---|
public Vec3d()
public Vec3d(double x, double y, double z)
x
- the x-coordinatey
- the y-coordinatez
- the z-coordinateMethod Detail |
---|
public Vec3d add(Vec3d vec)
vec
- the vector to add to the calling vector.
public void addToMe(Vec3d vec)
vec
- the vector to add to the calling vector.public Vec3d clone()
clone
in class Object
public Vec3d cross(Vec3d vec)
vec
- the second vector in the cross product.
public void crossMe(Vec3d vec)
vec
- the second vector in the cross product.public double dot(Vec3d vec)
vec
- the vector to multiply the calling vector by.
public double magnitude()
public Vec3d minus(Vec3d vec)
vec
- the vector to subtract from the calling vector.
public void minusFromMe(Vec3d vec)
vec
- the vector to subtract from the calling vector.public Vec3d negate()
public void negateMe()
public Vec3d normalize()
public void normalizeMe()
public Vec3d scale(double magnitude)
magnitude
- the scalar to multiple the vector by.
public void scaleMe(double magnitude)
magnitude
- the scalar to multiple the vector by.public void setXYZ(double x, double y, double z)
x
- the x-coordinatey
- the y-coordinatez
- the z-coordinatepublic void setXYZ(Vec3d vec)
vec
- the vector to copy xyz-values from.public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |