Go to the previous, next section.

Vector Math Operations

A number of vector-vector operations are provided. These include addition, subtraction, multiplication and division. Either a new matrix can be created (i.e. x = y + z) or the result can be stored into one of the operands (i.e. x += y). Also, the method dot calculates the dot product of two vectors.

The fract_vector class has methods that operate on every element of the vector. These include functions that add, subtract, multiply or divide a fraction or integer to every element.

A number of miscellaneous math operations on vectors are also available. The method inverse returns a fract_vector where every element is the inverse of the original vector. The proportional method checks to see if two vectors are proportional (i.e. all the corresponding elements have the same ratio). The reduce_magnitude method will try to maximally reduce the numerator of all the fractions in the vector.

The projection method takes a fract_vector as an argument and returns a fract_vector representing the point that's the projection of the current vector onto the line spanned by the argument vector. Let a be the argument, b be the current vector, and p be the resulting point. Also let aT be the transpose of a. The projection is calculated using the following equation: p = a * (aT * b / aT * a).

Go to the previous, next section.