Math Library
C4Vector3D.h

class Vector3D

The Vector3D class encapsulates a 3D vector.
Definition

class Vector3D

Member Functions
Vector3D::Set Sets all three components of a vector.
Vector3D::Normalize Normalizes a 3D vector.
Vector3D::RotateAboutX Rotates a vector about the x-axis.
Vector3D::RotateAboutY Rotates a vector about the y-axis.
Vector3D::RotateAboutZ Rotates a vector about the z-axis.
Vector3D::RotateAboutAxis Rotates a vector about a given axis.
Data Members
float   x; The x-coordinate.
float   y; The y-coordinate.
float   z; The z-coordinate.
Constructor

Vector3D();

Vector3D(float r, float s, float t);

Parameters
r The value of the x-coordinate.
s The value of the y-coordinate.
t The value of the z-coordinate.
Description
The Vector3D class is used to store a three-dimensional direction vector having floating-point components x, y, and z. A direction vector stored in this class is assumed to have a w-coordinate of 0 whenever it needs to be converted to a four-dimensional representation. Three-dimensional points (for which the w-coordinate is 1) should be stored using the Point3D class.

The default constructor leaves the components of the vector undefined. If the values r, s, and t are supplied, then they are assigned to the x, y, and z components of the vector, respectively.
Overloaded Operators
floatoperator [](long k); Returns a reference to the k-th component of a vector. The value of k must be 0, 1, or 2.
const floatoperator [](long k) const; Returns a constant reference to the k-th component of a vector. The value of k must be 0, 1, or 2.
Vector3D& operator +=(const Vector3D& v); Adds the vector v.
Vector3D& operator -=(const Vector3D& v); Subtracts the vector v.
Vector3D& operator *=(float t); Multiplies by the scalar t.
Vector3D& operator /=(float t); Divides by the scalar t.
Vector3D& operator %=(const Vector3D& v); Calculates the cross product with the vector v.
Vector3D& operator &=(const Vector3D& v); Calculates the componentwise product with the vector v.
Nonmember Operations
Vector3D operator -(const Vector3D& v); Returns the negation of the vector v.
Vector3D operator +(const Vector3D& v1, const Vector3D& v2); Returns the sum of the vectors v1 and v2.
Vector3D operator -(const Vector3D& v1, const Vector3D& v); Returns the difference of the vectors v1 and v2.
Vector3D operator *(const Vector3D& v, float t); Returns the product of the vector v and the scalar t.
Vector3D operator *(float t, const Vector3D& v); Returns the product of the vector v and the scalar t.
Vector3D operator /(const Vector3D& v, float t); Returns the product of the vector v and the inverse of the scalar t.
float operator *(const Vector3D& v1, const Vector3D& v2); Returns the dot product of the vectors v1 and v2.
Vector3D operator %(const Vector3D& v1, const Vector3D& v2); Returns the cross product of the vectors v1 and v2
Vector3D operator &(const Vector3D& v1, const Vector3D& v2); Returns the componentwise product of the vectors v1 and v2
bool operator ==(const Vector3D& v1, const Vector3D& v2); Returns a boolean value indicating the equality of the two vectors v1 and v2.
bool operator !=(const Vector3D& v1, const Vector3D& v2); Returns a boolean value indicating the inequality of the two vectors v1 and v2.
float Magnitude(const Vector3D& v); Returns the magnitude of the vector v.
float InverseMag(const Vector3D& v); Returns the inverse magnitude of the vector v.
float SquaredMag(const Vector3D& v); Returns the squared magnitude of the vector v.
float Dot(const Vector3D& v1, const Vector3D& v2); Returns the dot product between v1 and v2.
Vector3D Cross(const Vector3D& v1, const Vector3D& v2); Returns the cross product between v1 and v2.
Vector3D ProjectOnto(const Vector3D& v1, const Vector3D& v2); Returns the projection of v1 onto v2 scaled by the squared magnitude of v2.
See Also
Point3D

Vector4D