|
Sprites for Processing
V2.1
|
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 |
( 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.
| 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.
| x | the x coordinate. |
| y | the y coordinate. |
| z | the y coordinate. |
| sprites.utils.DVector.DVector | ( | double | x, |
| double | y | ||
| ) |
Constructor for a 2D vector: z coordinate is set to 0.
| 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 )
| v | the vector to be added |
| void sprites.utils.DVector.add | ( | double | x, |
| double | y, | ||
| double | z | ||
| ) |
| x | x component of the vector |
| y | y component of the vector |
| z | z component of the vector |
Add two vectors
| v1 | a vector |
| v2 | another vector |
Add two vectors into a target vector
| target | the target vector (if null, a new vector will be created) |
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 )
| v1 | the x, y, and z components of a PVector |
| v2 | the 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 )
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 )
| v | the vector to calculate the cross product |
| v | any variable of type PVector |
| target | PVector to store the result |
| v1 | any variable of type PVector |
| v2 | any variable of type PVector |
| target | PVector 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 )
| v | the x, y, and z coordinates of a PVector |
| v1 | any variable of type PVector |
| v2 | any variable of type PVector |
| 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 )
| n | the value to divide by |
Divide a vector by a scalar and return the result in a new vector.
| v | any variable of type PVector |
| n | the number to divide with the vector |
Divide a vector by a scalar and store the result in another vector.
| v | any variable of type PVector |
| n | the number to divide with the vector |
| target | PVector to store the result |
| void sprites.utils.DVector.div | ( | DVector | v | ) |
Divide each element of one vector by the elements of another vector.
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 )
| v | any variable of type PVector |
| double sprites.utils.DVector.dot | ( | double | x, |
| double | y, | ||
| double | z | ||
| ) |
| x | x component of the vector |
| y | y component of the vector |
| z | z component of the vector |
| v1 | any variable of type PVector |
| v2 | any 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 | ) |
| target |
| double sprites.utils.DVector.heading2D | ( | ) |
Calculate the angle of rotation for this vector (only 2D vectors)
| void sprites.utils.DVector.lerp | ( | DVector | v, |
| double | amt | ||
| ) |
Linear interpolate the vector to another vector
| PVector | the vector to lerp to |
| amt | The 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 )
| max | the 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.
| 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 )
| n | the number to multiply with the vector |
| v | the vector to multiply by the scalar |
Multiply a vector by a scalar, and write the result into a target PVector.
| target | PVector to store the result |
| v1 | the x, y, and z components of a PVector |
| v2 | the 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 )
| target | Set to null to create a new vector |
| void sprites.utils.DVector.rotate | ( | double | theta | ) |
Rotate the vector by an angle (only 2D vectors), magnitude remains the same
| theta | the 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 )
| x | the x component of the vector |
| y | the y component of the vector |
| z | the z component of the vector |
| void sprites.utils.DVector.set | ( | DVector | v | ) |
| v | any 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.
| source | array 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 )
| len | the new length for this vector |
Sets the magnitude of this vector, storing the result in another vector.
| target | Set to null to create a new vector |
| len | the new length for the new vector |
| 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 )
| v | any variable of type PVector |
| void sprites.utils.DVector.sub | ( | double | x, |
| double | y, | ||
| double | z | ||
| ) |
| x | the x component of the vector |
| y | the y component of the vector |
| z | the z component of the vector |
Subtract one vector from another
| v1 | the x, y, and z components of a PVector object |
| v2 | the x, y, and z components of a PVector object |
Subtract one vector from another and store in another vector
| v1 | the x, y, and z components of a PVector object |
| v2 | the x, y, and z components of a PVector object |
| target | PVector to store the result |
|
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 )