#AVector
Vector class for Arduino
based on Processing
's PVector class by Dan Shiffman, Ben Fry and Casey Reas.
My inspiration for writing this is Dan Shiffman's awesome book The Nature of Code, which he has graciously posted on his website in its entirety. It's definitely worth buying a print edition though. You wont regret it!
- Download the latest release from gitHub.
- Unzip and modify the Folder name to "AVector" (Remove the '-version')
- Paste the modified folder on your Library folder (On your
Libraries
folder inside Sketchbooks or Arduino software).
A class that describes a 2D vector. This can be used to describe a vector like velocity or acceleration, or used to describe a position.
This class also includes common vector operations (addition/subtraction, rotation, dot product etc).
//Simple AVector instance
AVector myVector(x, y);
//This will declare an AVector with x = 0 and y = 0:
AVector myVector(); // == AVector myVector(0, 0)
//Simple AVector instance
AVector myVector(4, 5);
//To access stored component values:
myVector.x(); // returns 4
myVector.y(); // returns 5
//To change stored component values:
myVector.set(8, 10);
myVector.x(); // returns 8
myVector.y(); // returns 10
// Also can be set from existing AVector object
AVector newVector(9, 12);
myVector.set(&newVector);
myVector.x(); // returns 9
myVector.y(); // returns 12
##Libary Reference
#####Initialize:
AVector::AVector(int x = 0, int y = 0)
Initialize new AVector object
#####Access Component Values:
int
AVector::x()
- return x componentint
AVector::y()
- return y component
#####Set Component Values:
AVector
AVector::set(int x, int y)
- set x,y coordinates from integer values and return new AVector objectAVector
AVector::set(AVector *otherVector)
- set x,y coordinates from AVector object and return new AVector object
#####Vector Operations:
AVector
AVector::add(int x, int y)
- add integer components to AVector object and return new AVector objectAVector
AVector::add(AVector *otherVector)
- add components of two AVector objects and return new AVector objectAVector
AVector::sub(int x, int y)
- subtract integer components from AVector object and return new AVector objectAVector
AVector::sub(AVector *otherVector)
- subtract components of two AVector objects and return new AVector objectAVector
AVector::mult(int scaler)
- multiply (or scale) vector by arbitrary integer value and return new AVector objectAVector
AVector::div(int scaler)
- divide (or scale) vector by arbitrary integer value and return new AVector objectAVector
AVector::setMag(float newMagnitude)
- set component values from vector magnitude (hypotenuse) and return new AVector object