C++ documentation C documentation

Three dimensional vectors having x, y and z components.

Vectors can use many of the operators that you can use with more basic types. For example:

Assignment:

Vector3D vec1(1,2,3);

Vector3D vec2();

vec2 = vec1; // Set vec2 to the same values as used by vec1

Test for equality or inequality:

if( vec1 == vec2){

// Both vectors are identical

}

if( vec1 != vec2){

// The vectors are not identical

}

Addition:

vec3 = vec1 + vec2; // Add two vectors and store in a third

vec2 += vec1; // vec2 = vec2 + vec1

Subtraction:

vec3 = vec1 - vec2; // Subtract two vectors and store in a third

vec2 -= vec1; // vec2 = vec2 - vec1

Scaling:

vec2 = vec1 * 3.5; // Multiply each component of vec1 and store in vec2

vec2 *= 5; // Multiply each component of vec2 and store back in vec2

Method

- Vector3D - Constructs a new vector object.
- length - Returns the magnitude of the vector.
- length2 - Returns the magnitude squared of the vector.
- set - Set the x,y,z components of a vector to new values.
- normalise - Scale the vector so that it has a magnitude of 1.
- dot - Returns the dot product of this vector with another specified vector.
- cross - Returns the cross product of this vector with another vector. The returned vector is at right angles to the other two.
- dump - Print the contents of the vector to the specified output stream.
- radians - Returns the angle, in radians, between this vector and another one.