LibTrace

Programming - The Vector class

There 2 types of "Vector" called "Vector2D" and "Vector3D", "Vector" is simply a "typedef" to "Vector3D".
Each "vector" has the appropriate "x", "y" and "z" variables as public and also a "valid" variable. This "valid" variable is used to specify simply if the "vector" is valid or not. It's used a lot internally and externally in some special cases.

Note: Where I say "Vector" the function applies to both "Vector2D" and "Vector3D"
Vector::Vector(bool v)
Vector2D::Vector2D(double nx, double ny)
Vector3D::Vector3D(double nx, double ny, double nz)

void Vector::normalize(void)
double Vector::magnitude(void)
void Vector::full_dump(void) const
Vector rotate(Vector v, Vector axis, double angle)
double dot(Vector v, Vector w)
Vector cross(Vector v, Vector w)
And of course the basic arithmatic operators ("+", "-", "*" and "/") have been overloaded.



Vector::Vector(bool v)
This constructor simply sets the initial value of "valid".
Vector2D::Vector2D(double nx, double ny)
This constructor sets the initial values of "x" and "y".
Vector3D::Vector3D(double nx, double ny, double nz)
This constructor sets the initial values of "x", "y" and "z".
void Vector::normalize(void)
This function adjusts the vector so that it has a length of 1 unit. The direction is unaffected.
double Vector::magnitude(void)
This function returns the length of the vector.
void Vector::full_dump(void) const
This function outputs details of the vector to "cout".
Vector rotate(Vector v, Vector axis, double angle)
This rotates "v" around the axis "axis" by "angle" radians. "Vector2D"'s and "Vector3D"'s cannot be mixed in this function.
double dot(Vector v, Vector w)
This function finds the dot product of "v" and "w". "Vector2D"'s and "Vector3D"'s cannot be mixed in this function.
Vector cross(Vector v, Vector w)
This function finds the cross product of "v" and "w". "Vector2D"'s and "Vector3D"'s cannot be mixed in this function.