libnxter  0.1
Data Structures | Functions
Vector.nxc File Reference

A simple 3-components vector implementation (2D point + direction) More...

#include "Debug.nxc"
#include "Matrix.nxc"
Include dependency graph for Vector.nxc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Vector
 A vector that represents a 2D point by x-y coordinates and a direction angle. More...
 

Functions

long VectorGet (Vector &a, int i)
 Gets the vector members with an index number rather than component names. Useful in a loop.
 
void VectorSet (Vector &a, int i, long value)
 Sets the vector members with an index number rather than component names. Useful in a loop.
 
long VectorGetDistance (Vector &a)
 Gets the polar distance of the given vector. It's the distance of its x-y coordicate from origin.
 
int VectorGetAngle (Vector &a)
 Gets the polar angle of the given vectors. It's the angle of its x-y coordinate from origin. it ranges from 0 to 360, 0 on x-axis facing +ve side and increasing anti-clockwise.
 
long VectorGetDistanceVec (Vector &a, Vector &b)
 Gets the distance between given two vectors.
 
long VectorGetAngleVec (Vector &a, Vector &b)
 Gets the angle of the line formed by the given two vectors.
 
void VectorInit (Vector &a, long x, long y, long theta)
 Initializes the vector with given x, y and theta components.
 
void VectorInitPolar (Vector &a, long distance, int angle, int theta)
 Initializes the vector with given distance and angle polar components. More...
 
void VectorInitBound (Vector &retVec, long x, long y)
 Initializes the vector into a bound vector with the point given by x and y. Bound vector is a vector originating from world origin and pointing towards the given point. Hence theta is the direction of the (x,y) point w.r.t origin.
 
void VectorTranslate (Vector &a, long distance, int angle)
 Translate the vector point to a new point moved the given distance towards the given direction angle. More...
 
void VectorAdd (Vector &a, Vector &b)
 Adds vector b to a. i.e. a += b.
 
void VectorSubtract (Vector &a, Vector &b)
 Subtracts vector b from a. i.e. a -= b.
 
void VectorScale (Vector &a, long S)
 Scales x and y vector components by the given factor. i.e. a = a * S.
 
void VectorReduce (Vector &a, long S)
 Reduces x and y vector components by the given factor. i.e. a = a / S.
 
void VectorRotate (Vector &vec, long theta)
 Rotates the point in the vector by given angle. The direction component in the vector is not touched.
 
void VectorRotateAtPoint (Vector &vec, long theta, long pivotX, long pivotY)
 Rotates the point in the vector by given angle around the pivot point given by pivotX and pivotY. The direction component in the vector is not touched.
 
void VectorTransform (Vector &vec, Matrix &matrix, Vector &retVec)
 Transforms the given vector with the given transformation matrix and returns the transformed vector in retVec. retVector must be different from input vector because they are passed as reference. Vector transformation is just multiplying the (column) vector with the transformation matrix.
 

Detailed Description

A simple 3-components vector implementation (2D point + direction)

Note that this is not a 3D vector as in 3-dimentional coordinates system. It is more of a convenient package to put together a 2D point and a direction component associated with it. This is an important distinciton because many of the vector operations on this are only applicable to the x-y point, such as rotating it. For actual 3D vector, use Matrix instead.

Definition in file Vector.nxc.

Function Documentation

void VectorInitPolar ( Vector a,
long  distance,
int  angle,
int  theta 
)

Initializes the vector with given distance and angle polar components.

Note that 'angle' in the polar coordinate components is not the theta in the vector. 'angle' is part of coordinate that describes the location of of the point. theta, on the other hand, is the direction of the point and could be facing anywhere.

Definition at line 137 of file Vector.nxc.

References Vector::theta, Vector::x, and Vector::y.

void VectorTranslate ( Vector a,
long  distance,
int  angle 
)

Translate the vector point to a new point moved the given distance towards the given direction angle.

Note that the theta (direction) component in the vector is unaffected.

Definition at line 163 of file Vector.nxc.

References Vector::x, and Vector::y.

Referenced by Odometer2SetDriftCorrection(), SonarFindObject(), and SonarFindObjectAtAngle().