Skip to content
fpdotmonkey edited this page Sep 17, 2013 · 1 revision

To use this library, type the following in your program:

#include "vector.h"
#include "typedefs.h"

Since this is a simple vector math library, you can both for robotic and non-robotic things; it doesn't use any of the RobotC APIs.

The Functions

magnitude()

long magnitude(vect vector)

(long) Calculates the magnitude of the vector vector

Parameter Explanation Data Type
vector A 3-D vector vect
vect velocity = { 20, 40, 80 };
long avg_speed = magnitude(velocity);

directionXY()

int directionXY(vect vector)

(int) Calculates the angle made by the vector in the XY plane.

Parameter Explanation Data Type
vector A 3-D vector vect
vect velocity = { 20, 40, 80 };
int dir_velocityXY = directionXY(velocity);

directionXZ

int directionXZ(vect vector)

(int) Calculates the angle made by the vector in the XZ plane.

Parameter Explanation Data Type
vector A 3-D vector vect
vect velocity = { 20, 40, 80 };
int dir_velocityXZ = directionXZ(velocity);

add()

vect add(vect vect1, vect vect2)

(vect) Adds two vectors together. Make one of the vectors negative for subtraction.

Parameter Explanation Data Type
vect1 A 3-D vector vect
vect2 A 3-D vector vect
vect velocity1 = { 20, 40, 80 };
vect velocity2 = { 30, 90, 270 };

vect tot_velocity = add(velocity1, velocity2);

mult()

vect mult(long scalar, vect vector)

(vect) Multiplies a vector by a scalar. Make the scalar a fraction for division.

Parameter Explanation Data Type
scalar The number you wish to multiply the vector by long
vector A 3-D vector vect
vect velocity = { 20, 40, 80 };

vect double_velocity = mult(2, velocity);

dot_prod()

vect dot_prod(vect vect1, vect vect2)

(vect) Calculates the dot product of two vectors.

Parameter Explanation Data Type
vect1 A 3-D vector vect
vect2 A 3-D vector vect
vect force = { 10, 20, 30 };
vect displacement = { 5, 10, 15 };

vect mechanical_work = dot_prod(force, displacement);

unit_vector()

vect unit_vector(vect vector)

(vect) Returns a vector with the same direction as vector, but with a magnitude of 1

Parameter Explanation Data Type
vector A 3-D vector vect
vect velocity = { 10, 20, 40 };
long mag = magnitude(velocity);

vect velocity_double = mult(mag * 2, unit_vector(velocity);

equivalent()

bool equivalent(vect vect1, vect vect2)

(bool) Checks if vect1 is the same as vect2.

Parameter Explanation Data Type
vect1 A 3-D vector vect
vect2 A 3-D vector vect
vect velocity1 = { a, b, c }; // where a, b, and c are pre-defined values
vect velocity2 = { b, a, c };

if (equivalent(velocity1, velocity2)) {
  printf("b == a");
}

Clone this wiki locally