C++ documentation C documentation

Two dimensional vectors having x and ycomponents.

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

Assignment:

Vector2D vec1(1,2);

Vector2D 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

- Vector2D - 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 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.
- dump - Print the contents of the vector to the specified output stream.
- radians - Returns the angle, in radians, between this vector and another one.