|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnoc.Vector3D
A class to describe a two or three dimensional vector.
Created for use in examples from the Nature of Code course at ITP.
http://www.shiffman.net/
http://www.shiffman.net/teaching/the-nature-of-code
| Field Summary | |
float |
x
The x component of the vector. |
float |
y
The y component of the vector. |
float |
z
The z component of the vector. |
| Constructor Summary | |
Vector3D()
Constructor for an empty vector: x, y, and z are set to 0. |
|
Vector3D(float x_,
float y_)
Constructor for a 2D vector: z coordinate is set to 0. |
|
Vector3D(float x_,
float y_,
float z_)
Constructor for a 3D vector. |
|
| Method Summary | |
void |
add(Vector3D v)
Add a vector to this vector |
static Vector3D |
add(Vector3D v1,
Vector3D v2)
Add two vectors |
static float |
angleBetween(Vector3D v1,
Vector3D v2)
Calculate the angle between two vectors, using the dot product |
Vector3D |
copy()
Copy the vector |
static Vector3D |
copy(Vector3D v)
Copy the vector |
Vector3D |
cross(Vector3D v)
Calculate the cross product with another vector |
static float |
distance(Vector3D v1,
Vector3D v2)
Calculate the Euclidean distance between two points (considering a point as a vector object) |
void |
div(float n)
Divide this vector by a scalar |
static Vector3D |
div(Vector3D v1,
float n)
Divide a vector by a scalar |
float |
dot(Vector3D v)
Calculate the dot product with another vector |
float |
heading2D()
Calculate the angle of rotation for this vector (only 2D vectors) |
void |
limit(float max)
Limit the magnitude of this vector |
float |
magnitude()
Calculate the magnitude (length) of the vector |
void |
mult(float n)
Multiply this vector by a scalar |
static Vector3D |
mult(Vector3D v1,
float n)
Multiply a vector by a scalar |
void |
normalize()
Normalize the vector to length 1 (make it a unit vector) |
void |
setX(float x_)
Set the x coordinate. |
void |
setXYZ(float x_,
float y_,
float z_)
Set x,y, and z coordinates. |
void |
setXYZ(Vector3D v)
Set x,y, and z coordinates from a Vector3D object. |
void |
setY(float y_)
Set the y coordinate. |
void |
setZ(float z_)
Set the z coordinate. |
void |
sub(Vector3D v)
Subtract a vector from this vector |
static Vector3D |
sub(Vector3D v1,
Vector3D v2)
Subtract one vector from another |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public float x
public float y
public float z
| Constructor Detail |
public Vector3D(float x_,
float y_,
float z_)
x_ - the x coordinate.y_ - the y coordinate.z_ - the y coordinate.
public Vector3D(float x_,
float y_)
x_ - the x coordinate.y_ - the y coordinate.public Vector3D()
| Method Detail |
public void setX(float x_)
x_ - the x coordinate.public void setY(float y_)
y_ - the y coordinate.public void setZ(float z_)
z_ - the z coordinate.
public void setXYZ(float x_,
float y_,
float z_)
x_ - the x coordinate.y_ - the y coordinate.z_ - the z coordinate.public void setXYZ(Vector3D v)
v - the Vector3D object to be copiedpublic float magnitude()
public Vector3D copy()
public static Vector3D copy(Vector3D v)
v - the vector to be copied
public void add(Vector3D v)
v - the vector to be addedpublic void sub(Vector3D v)
v - the vector to be subtractedpublic void mult(float n)
n - the value to multiply bypublic void div(float n)
n - the value to divide bypublic float dot(Vector3D v)
public Vector3D cross(Vector3D v)
public void normalize()
public void limit(float max)
max - the maximum length to limit this vectorpublic float heading2D()
public static Vector3D add(Vector3D v1,
Vector3D v2)
v1 - a vectorv2 - another vector
public static Vector3D sub(Vector3D v1,
Vector3D v2)
v1 - a vectorv2 - another vector
public static Vector3D div(Vector3D v1,
float n)
v1 - a vectorn - scalar
public static Vector3D mult(Vector3D v1,
float n)
v1 - a vectorn - scalar
public static float distance(Vector3D v1,
Vector3D v2)
v1 - a vectorv2 - another vector
public static float angleBetween(Vector3D v1,
Vector3D v2)
v1 - a vectorv2 - another vector
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||