Sprites for Processing  V2.1
 All Classes Functions Variables
sprites.utils.DVector Class Reference
Inheritance diagram for sprites.utils.DVector:

Public Member Functions

 DVector ()
 
 DVector (double x, double y, double z)
 
 DVector (double x, double y)
 
void set (double x, double y, double z)
 Set the x, y, and z component of the vector. More...
 
void set (DVector v)
 
void set (double[] source)
 
DVector get ()
 Get a copy of the vector. More...
 
double[] get (double[] target)
 
double mag ()
 Calculate the magnitude of the vector. More...
 
double magSq ()
 
void add (DVector v)
 Adds x, y, and z components to a vector, one vector to another, or two independent vectors. More...
 
void add (double x, double y, double z)
 
void sub (DVector v)
 Subtract x, y, and z components from a vector, one vector from another, or two independent vectors. More...
 
void sub (double x, double y, double z)
 
void mult (double n)
 Multiply a vector by a scalar or one vector by another. More...
 
void mult (DVector v)
 
void div (double n)
 Divide a vector by a scalar or one vector by another. More...
 
void div (DVector v)
 
double dist (DVector v)
 Calculate the distance between two points. More...
 
double dot (DVector v)
 Calculate the dot product of two vectors. More...
 
double dot (double x, double y, double z)
 
DVector cross (DVector v)
 Calculate and return the cross product. More...
 
DVector cross (DVector v, DVector target)
 
void normalize ()
 Normalize the vector to a length of 1. More...
 
DVector normalize (DVector target)
 
void limit (double max)
 Limit the magnitude of the vector. More...
 
void setMag (double len)
 
DVector setMag (DVector target, double len)
 
double heading2D ()
 
void rotate (double theta)
 
void lerp (DVector v, double amt)
 
void lerp (double x, double y, double z, double amt)
 
double lerp (double start, double stop, double amt)
 
String toString ()
 
double[] array ()
 Return a representation of the vector as a double array. More...
 
boolean equals (Object obj)
 
int hashCode ()
 

Static Public Member Functions

static DVector add (DVector v1, DVector v2)
 
static DVector add (DVector v1, DVector v2, DVector target)
 
static DVector sub (DVector v1, DVector v2)
 
static DVector sub (DVector v1, DVector v2, DVector target)
 
static DVector mult (DVector v, double n)
 
static DVector mult (DVector v, double n, DVector target)
 
static DVector mult (DVector v1, DVector v2)
 
static DVector mult (DVector v1, DVector v2, DVector target)
 
static DVector div (DVector v, double n)
 
static DVector div (DVector v, double n, DVector target)
 
static DVector div (DVector v1, DVector v2)
 
static DVector div (DVector v1, DVector v2, DVector target)
 
static double dist (DVector v1, DVector v2)
 
static double dot (DVector v1, DVector v2)
 
static DVector cross (DVector v1, DVector v2, DVector target)
 
static double angleBetween (DVector v1, DVector v2)
 Calculate and return the angle between two vectors. More...
 

Public Attributes

double x
 The x component of the vector. More...
 
double y
 The y component of the vector. More...
 
double z
 The z component of the vector. More...
 

Protected Attributes

transient double[] array
 

Detailed Description

( begin auto-generated from PVector.xml )

A class to describe a two or three dimensional vector. This datatype stores two or three variables that are commonly used as a position, velocity, and/or acceleration. Technically, position is a point and velocity and acceleration are vectors, but this is often simplified to consider all three as vectors. For example, if you consider a rectangle moving across the screen, at any given instant it has a position (the object's location, expressed as a point.), a velocity (the rate at which the object's position changes per time unit, expressed as a vector), and acceleration (the rate at which the object's velocity changes per time unit, expressed as a vector). Since vectors represent groupings of values, we cannot simply use traditional addition/multiplication/etc. Instead, we'll need to do some "vector" math, which is made easy by the methods inside the PVector class.

The methods for this class are extensive. For a complete list, visit the developer's reference.

( end auto-generated )

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.

Constructor & Destructor Documentation

sprites.utils.DVector.DVector ( )

Constructor for an empty vector: x, y, and z are set to 0.

sprites.utils.DVector.DVector ( double  x,
double  y,
double  z 
)

Constructor for a 3D vector.

Parameters
xthe x coordinate.
ythe y coordinate.
zthe y coordinate.
sprites.utils.DVector.DVector ( double  x,
double  y 
)

Constructor for a 2D vector: z coordinate is set to 0.

Member Function Documentation

void sprites.utils.DVector.add ( DVector  v)

Adds x, y, and z components to a vector, one vector to another, or two independent vectors.

( begin auto-generated from PVector_add.xml )

Adds x, y, and z components to a vector, adds one vector to another, or adds two independent vectors together. The version of the method that adds two vectors together is a static method and returns a PVector, the others have no return value – they act directly on the vector. See the examples for more context.

( end auto-generated )

Parameters
vthe vector to be added
void sprites.utils.DVector.add ( double  x,
double  y,
double  z 
)
Parameters
xx component of the vector
yy component of the vector
zz component of the vector
static DVector sprites.utils.DVector.add ( DVector  v1,
DVector  v2 
)
static

Add two vectors

Parameters
v1a vector
v2another vector
static DVector sprites.utils.DVector.add ( DVector  v1,
DVector  v2,
DVector  target 
)
static

Add two vectors into a target vector

Parameters
targetthe target vector (if null, a new vector will be created)
static double sprites.utils.DVector.angleBetween ( DVector  v1,
DVector  v2 
)
static

Calculate and return the angle between two vectors.

( begin auto-generated from PVector_angleBetween.xml )

Calculates and returns the angle (in radians) between two vectors.

( end auto-generated )

Parameters
v1the x, y, and z components of a PVector
v2the x, y, and z components of a PVector
double [] sprites.utils.DVector.array ( )

Return a representation of the vector as a double array.

( begin auto-generated from PVector_array.xml )

Return a representation of this vector as a double array. This is only for temporary use. If used in any other fashion, the contents should be copied by using the PVector.get() method to copy into your own array.

( end auto-generated )

DVector sprites.utils.DVector.cross ( DVector  v)

Calculate and return the cross product.

( begin auto-generated from PVector_cross.xml )

Calculates and returns a vector composed of the cross product between two vectors.

( end auto-generated )

Parameters
vthe vector to calculate the cross product
DVector sprites.utils.DVector.cross ( DVector  v,
DVector  target 
)
Parameters
vany variable of type PVector
targetPVector to store the result
static DVector sprites.utils.DVector.cross ( DVector  v1,
DVector  v2,
DVector  target 
)
static
Parameters
v1any variable of type PVector
v2any variable of type PVector
targetPVector to store the result
double sprites.utils.DVector.dist ( DVector  v)

Calculate the distance between two points.

( begin auto-generated from PVector_dist.xml )

Calculates the Euclidean distance between two points (considering a point as a vector object).

( end auto-generated )

Parameters
vthe x, y, and z coordinates of a PVector
static double sprites.utils.DVector.dist ( DVector  v1,
DVector  v2 
)
static
Parameters
v1any variable of type PVector
v2any variable of type PVector
Returns
the Euclidean distance between v1 and v2
void sprites.utils.DVector.div ( double  n)

Divide a vector by a scalar or one vector by another.

( begin auto-generated from PVector_div.xml )

Divides a vector by a scalar or divides one vector by another.

( end auto-generated )

Parameters
nthe value to divide by
static DVector sprites.utils.DVector.div ( DVector  v,
double  n 
)
static

Divide a vector by a scalar and return the result in a new vector.

Parameters
vany variable of type PVector
nthe number to divide with the vector
Returns
a new vector that is v1 / n
static DVector sprites.utils.DVector.div ( DVector  v,
double  n,
DVector  target 
)
static

Divide a vector by a scalar and store the result in another vector.

Parameters
vany variable of type PVector
nthe number to divide with the vector
targetPVector to store the result
void sprites.utils.DVector.div ( DVector  v)

Divide each element of one vector by the elements of another vector.

static DVector sprites.utils.DVector.div ( DVector  v1,
DVector  v2 
)
static

Divide each element of one vector by the individual elements of another vector, and return the result as a new PVector.

double sprites.utils.DVector.dot ( DVector  v)

Calculate the dot product of two vectors.

( begin auto-generated from PVector_dot.xml )

Calculates the dot product of two vectors.

( end auto-generated )

Parameters
vany variable of type PVector
Returns
the dot product
double sprites.utils.DVector.dot ( double  x,
double  y,
double  z 
)
Parameters
xx component of the vector
yy component of the vector
zz component of the vector
static double sprites.utils.DVector.dot ( DVector  v1,
DVector  v2 
)
static
Parameters
v1any variable of type PVector
v2any variable of type PVector
DVector sprites.utils.DVector.get ( )

Get a copy of the vector.

( begin auto-generated from PVector_get.xml )

Gets a copy of the vector, returns a PVector object.

( end auto-generated )

double [] sprites.utils.DVector.get ( double[]  target)
Parameters
target
double sprites.utils.DVector.heading2D ( )

Calculate the angle of rotation for this vector (only 2D vectors)

Returns
the angle of rotation
void sprites.utils.DVector.lerp ( DVector  v,
double  amt 
)

Linear interpolate the vector to another vector

Parameters
PVectorthe vector to lerp to
amtThe amt parameter is the amount to interpolate between the two vectors where 1.0 equal to the new vector 0.1 is very near the new vector, 0.5 is half-way in between.
void sprites.utils.DVector.limit ( double  max)

Limit the magnitude of the vector.

( begin auto-generated from PVector_limit.xml )

Limit the magnitude of this vector to the value used for the max parameter.

( end auto-generated )

Parameters
maxthe maximum magnitude for the vector
double sprites.utils.DVector.mag ( )

Calculate the magnitude of the vector.

( begin auto-generated from PVector_mag.xml )

Calculates the magnitude (length) of the vector and returns the result as a double (this is simply the equation sqrt(x*x + y*y + z*z).)

( end auto-generated )

double sprites.utils.DVector.magSq ( )

Calculate the squared magnitude of the vector Faster if the real length is not required in the case of comparing vectors, etc.

Returns
squared magnitude of the vector
void sprites.utils.DVector.mult ( double  n)

Multiply a vector by a scalar or one vector by another.

( begin auto-generated from PVector_mult.xml )

Multiplies a vector by a scalar or multiplies one vector by another.

( end auto-generated )

Parameters
nthe number to multiply with the vector
static DVector sprites.utils.DVector.mult ( DVector  v,
double  n 
)
static
Parameters
vthe vector to multiply by the scalar
static DVector sprites.utils.DVector.mult ( DVector  v,
double  n,
DVector  target 
)
static

Multiply a vector by a scalar, and write the result into a target PVector.

Parameters
targetPVector to store the result
static DVector sprites.utils.DVector.mult ( DVector  v1,
DVector  v2 
)
static
Parameters
v1the x, y, and z components of a PVector
v2the x, y, and z components of a PVector
void sprites.utils.DVector.normalize ( )

Normalize the vector to a length of 1.

( begin auto-generated from PVector_normalize.xml )

Normalize the vector to length 1 (make it a unit vector).

( end auto-generated )

DVector sprites.utils.DVector.normalize ( DVector  target)
Parameters
targetSet to null to create a new vector
Returns
a new vector (if target was null), or target
void sprites.utils.DVector.rotate ( double  theta)

Rotate the vector by an angle (only 2D vectors), magnitude remains the same

Parameters
thetathe angle of rotation
void sprites.utils.DVector.set ( double  x,
double  y,
double  z 
)

Set the x, y, and z component of the vector.

( begin auto-generated from PVector_set.xml )

Sets the x, y, and z component of the vector using three separate variables, the data from a PVector, or the values from a double array.

( end auto-generated )

Parameters
xthe x component of the vector
ythe y component of the vector
zthe z component of the vector
void sprites.utils.DVector.set ( DVector  v)
Parameters
vany variable of type PVector
void sprites.utils.DVector.set ( double[]  source)

Set the x, y (and maybe z) coordinates using a double[] array as the source.

Parameters
sourcearray to copy from
void sprites.utils.DVector.setMag ( double  len)

( begin auto-generated from PVector_setMag.xml )

Set the magnitude of this vector to the value used for the len parameter.

( end auto-generated )

Parameters
lenthe new length for this vector
DVector sprites.utils.DVector.setMag ( DVector  target,
double  len 
)

Sets the magnitude of this vector, storing the result in another vector.

Parameters
targetSet to null to create a new vector
lenthe new length for the new vector
Returns
a new vector (if target was null), or target
void sprites.utils.DVector.sub ( DVector  v)

Subtract x, y, and z components from a vector, one vector from another, or two independent vectors.

( begin auto-generated from PVector_sub.xml )

Subtracts x, y, and z components from a vector, subtracts one vector from another, or subtracts two independent vectors. The version of the method that substracts two vectors is a static method and returns a PVector, the others have no return value – they act directly on the vector. See the examples for more context.

( end auto-generated )

Parameters
vany variable of type PVector
void sprites.utils.DVector.sub ( double  x,
double  y,
double  z 
)
Parameters
xthe x component of the vector
ythe y component of the vector
zthe z component of the vector
static DVector sprites.utils.DVector.sub ( DVector  v1,
DVector  v2 
)
static

Subtract one vector from another

Parameters
v1the x, y, and z components of a PVector object
v2the x, y, and z components of a PVector object
static DVector sprites.utils.DVector.sub ( DVector  v1,
DVector  v2,
DVector  target 
)
static

Subtract one vector from another and store in another vector

Parameters
v1the x, y, and z components of a PVector object
v2the x, y, and z components of a PVector object
targetPVector to store the result

Member Data Documentation

transient double [] sprites.utils.DVector.array
protected

Array so that this can be temporarily used in an array context

double sprites.utils.DVector.x

The x component of the vector.

( begin auto-generated from PVector_x.xml )

The x component of the vector. This field (variable) can be used to both get and set the value (see above example.)

( end auto-generated )

double sprites.utils.DVector.y

The y component of the vector.

( begin auto-generated from PVector_y.xml )

The y component of the vector. This field (variable) can be used to both get and set the value (see above example.)

( end auto-generated )

double sprites.utils.DVector.z

The z component of the vector.

( begin auto-generated from PVector_z.xml )

The z component of the vector. This field (variable) can be used to both get and set the value (see above example.)

( end auto-generated )


The documentation for this class was generated from the following file: