|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectprocessing.core.PVector
public class PVector
A class to describe a two or three dimensional vector.
The result of all functions are applied to the vector itself, with the exception of cross(), which returns a new PVector (or writes to a specified 'target' PVector). That is, add() will add the contents of one vector to this one. Using add() with additional parameters allows you to put the result into a new PVector. Functions that act on multiple vectors also include static versions. Because creating new objects can be computationally expensive, most functions include an optional 'target' PVector, so that a new PVector object is not created with each operation.
Initially based on the Vector3D class by Dan Shiffman.
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 | |
---|---|
PVector()
Constructor for an empty vector: x, y, and z are set to 0. |
|
PVector(float x,
float y)
Constructor for a 2D vector: z coordinate is set to 0. |
|
PVector(float x,
float y,
float z)
Constructor for a 3D vector. |
Method Summary | |
---|---|
void |
add(float x,
float y,
float z)
|
void |
add(PVector v)
Add a vector to this vector |
static PVector |
add(PVector v1,
PVector v2)
Add two vectors |
static PVector |
add(PVector v1,
PVector v2,
PVector target)
Add two vectors into a target vector |
static float |
angleBetween(PVector v1,
PVector v2)
Calculate the angle between two vectors, using the dot product |
float[] |
array()
Return a representation of this vector as a float array. |
PVector |
cross(PVector v)
Return a vector composed of the cross product between this and another. |
PVector |
cross(PVector v,
PVector target)
Perform cross product between this and another vector, and store the result in 'target'. |
static PVector |
cross(PVector v1,
PVector v2,
PVector target)
|
float |
dist(PVector v)
Calculate the Euclidean distance between two points (considering a point as a vector object) |
static float |
dist(PVector v1,
PVector 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 |
void |
div(PVector v)
Divide each element of one vector by the elements of another vector. |
static PVector |
div(PVector v,
float n)
Divide a vector by a scalar and return the result in a new vector. |
static PVector |
div(PVector v,
float n,
PVector target)
|
static PVector |
div(PVector v1,
PVector v2)
Multiply each element of one vector by the individual elements of another vector, and return the result as a new PVector. |
static PVector |
div(PVector v1,
PVector v2,
PVector target)
Divide each element of one vector by the individual elements of another vector, and write the result into a target vector. |
float |
dot(float x,
float y,
float z)
|
float |
dot(PVector v)
Calculate the dot product with another vector |
PVector |
get()
Get a copy of this vector. |
float[] |
get(float[] target)
|
float |
heading2D()
Calculate the angle of rotation for this vector (only 2D vectors) |
void |
limit(float max)
Limit the magnitude of this vector |
float |
mag()
Calculate the magnitude (length) of the vector |
void |
mult(float n)
Multiply this vector by a scalar |
void |
mult(PVector v)
Multiply each element of one vector by the elements of another vector. |
static PVector |
mult(PVector v,
float n)
Multiply a vector by a scalar |
static PVector |
mult(PVector v,
float n,
PVector target)
Multiply a vector by a scalar, and write the result into a target PVector. |
static PVector |
mult(PVector v1,
PVector v2)
Multiply each element of one vector by the individual elements of another vector, and return the result as a new PVector. |
static PVector |
mult(PVector v1,
PVector v2,
PVector target)
Multiply each element of one vector by the individual elements of another vector, and write the result into a target vector. |
void |
normalize()
Normalize the vector to length 1 (make it a unit vector) |
PVector |
normalize(PVector target)
Normalize this vector, storing the result in another vector. |
void |
set(float[] source)
Set the x, y (and maybe z) coordinates using a float[] array as the source. |
void |
set(float x,
float y,
float z)
Set x, y, and z coordinates. |
void |
set(PVector v)
Set x, y, and z coordinates from a Vector3D object. |
void |
sub(float x,
float y,
float z)
|
void |
sub(PVector v)
Subtract a vector from this vector |
static PVector |
sub(PVector v1,
PVector v2)
Subtract one vector from another |
static PVector |
sub(PVector v1,
PVector v2,
PVector target)
|
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public float x
public float y
public float z
Constructor Detail |
---|
public PVector()
public PVector(float x, float y, float z)
x
- the x coordinate.y
- the y coordinate.z
- the y coordinate.public PVector(float x, float y)
x
- the x coordinate.y
- the y coordinate.Method Detail |
---|
public void set(float x, float y, float z)
x
- the x coordinate.y
- the y coordinate.z
- the z coordinate.public void set(PVector v)
v
- the PVector object to be copiedpublic void set(float[] source)
source
- array to copy frompublic PVector get()
public float[] get(float[] target)
public float mag()
public void add(PVector v)
v
- the vector to be addedpublic void add(float x, float y, float z)
public static PVector add(PVector v1, PVector v2)
v1
- a vectorv2
- another vector
public static PVector add(PVector v1, PVector v2, PVector target)
v1
- a vectorv2
- another vectortarget
- the target vector (if null, a new vector will be created)
public void sub(PVector v)
v
- the vector to be subtractedpublic void sub(float x, float y, float z)
public static PVector sub(PVector v1, PVector v2)
v1
- a vectorv2
- another vector
public static PVector sub(PVector v1, PVector v2, PVector target)
public void mult(float n)
n
- the value to multiply bypublic static PVector mult(PVector v, float n)
v
- a vectorn
- scalar
public static PVector mult(PVector v, float n, PVector target)
v
- a vectorn
- scalartarget
- PVector to store the result
public void mult(PVector v)
v
- the vector to multiply bypublic static PVector mult(PVector v1, PVector v2)
public static PVector mult(PVector v1, PVector v2, PVector target)
v1
- the first vectorv2
- the second vectortarget
- PVector to store the resultpublic void div(float n)
n
- the value to divide bypublic static PVector div(PVector v, float n)
v
- a vectorn
- scalar
public static PVector div(PVector v, float n, PVector target)
public void div(PVector v)
public static PVector div(PVector v1, PVector v2)
public static PVector div(PVector v1, PVector v2, PVector target)
v1
- the first vectorv2
- the second vectortarget
- PVector to store the resultpublic float dist(PVector v)
v
- another vector
public static float dist(PVector v1, PVector v2)
v1
- a vectorv2
- another vector
public float dot(PVector v)
public float dot(float x, float y, float z)
public PVector cross(PVector v)
public PVector cross(PVector v, PVector target)
public static PVector cross(PVector v1, PVector v2, PVector target)
public void normalize()
public PVector normalize(PVector target)
target
- Set to null to create a new vector
public void limit(float max)
max
- the maximum length to limit this vectorpublic float heading2D()
public static float angleBetween(PVector v1, PVector v2)
v1
- a vectorv2
- another vector
public java.lang.String toString()
toString
in class java.lang.Object
public float[] array()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |