PVector
Data / CompositeDescription
A class to describe a two or three dimensional vector. Commonly used to represent position, velocity, or direction.
Syntax
PVector v
PVector v(x, y)
PVector v(x, y, z)
Parameters
| Name | Type | Description |
|---|---|---|
| x | float | x component (optional) |
| y | float | y component (optional) |
| z | float | z component (optional) |
Returns
PVectorMethods
| mag() | Magnitude (length) of the vector |
| magSq() | Magnitude squared |
| add(PVector v) | Add another vector |
| sub(PVector v) | Subtract another vector |
| mult(float s) | Multiply by scalar |
| div(float s) | Divide by scalar |
| normalize() | Normalize to unit length |
| limit(float max) | Limit the magnitude |
| setMag(float m) | Set the magnitude |
| dot(PVector v) | Dot product |
| cross(PVector v) | Cross product |
| dist(PVector v) | Distance to another vector |
| heading() | Angle the vector makes with positive x-axis |
| angleBetween(PVector v) | Angle between two vectors |
| lerp(PVector v, float t) | Interpolate towards another vector |
| rotate(float angle) | Rotate by an angle (2D) |
| copy() | Return a copy |
| toString() | String representation |
| PVector::fromAngle(float a) | Create from angle (static) |
| PVector::random2D() | Random 2D unit vector (static) |
| PVector::random3D() | Random 3D unit vector (static) |
Under the Hood
Implementation in Processing.h / Processing.cpp:
Loading...