Module Linear

The module "linear" includes three class definitions: Vector, Matrix, and Quaternion.

1.0 Vector

A frequently needed class of objects in aerospace navigation analysis are three dimensional vectors and matrices. A three dimensional vector, for example, can be used to represent the position of an object in space. If we pick a reference point anywhere in space and define three cartesian axes originating at that point, then the coordinates of a position, x,y, and z form three numbers which we can represent as the components of a vector.

In order to use the class Vector, include the file "linear.h" in your program, then you may declare an object of that class thus:

Vector r(0.,0.,0.);

The object r is a vector and it has been initialized to the origin of the coordinate system which is the point (0.,0.,0.).

Operator overloading has been used to implement a simple vector algebra. The following operations are supported:

Vector Addition and Subtraction:

Example

Vector r1(1.,0.,0.);
Vector r2(0.,1.,0.);
Vector r3;
Vector r4;

r3 = r1 + r2;
r4 = r1 - r2;
printf("r3 = %f %f %f\n",r3.x,r3.y,r3.z);
printf("r4 = %f %f %f\n",r4.x,r4.y,r4.z);

The vector r3 will contain the values (1.,1.,0.) and the vector r4 will contain the values (1.,-1.,0.).

Scalar or "Dot" Product of Two Vectors

Example

Vector r1;
Vector r2;
double s;

s = r1 * r2;

The floating point number "s" contains the dot product of the two vectors r1 and r2.

A complete description of the Vector operations defined can be obtained from the comments within the implementation file, linear.cpp, and the header file, linear.h. Here is a complete list of the operations presently implemented:

//  Operations:
//            : Vector a(x1,y1,z1);
//            : Vector b(x2,y2,z2);
//            : Vector c;
//            : double s;  // a scalar value
//    add     : c = a + b;
//    sub     ; c = a - b;
//    dot     ; s = a*b;
//    cross   : c = a % b;
//    abs()   : s = a.abs();
//    multiply: c = a*s;       vector times a scalar
//    divide  : c = a/s;       vector divided by a scalar
//    normalize a vector :  c = a/a.abs();

2.0 Matrix

A three dimensional matrix is a collection of 9 numbers arranged in a square array. Here is a description of the Matrix class as defined in the module "linear.h."

//
// class Matrix      : This class is derived from vector and
//                   : adds basic matrix operations
// Initialization    : #include "linear.h"
//                   : Matrix A(m11,m12,m13,
//                              m21,m22,m23,
//                              m31,m32,m33);
//  Operations 
//  ============
//  Matrix times a matrix returns a matrix:
//  Matrix A;
//  Matrix B;
//  Matrix C;
//  C = A*B;
//
//  Matrix times a vector, returns a vector
//  Vector v;
//  Vector u;
//  u = A*v;
//  
//  Transpose:
//  C = A.transpose();
//
//  Inverse:
//  C = A.inverse();
//
//  Determinant:
//  double d = A.det();
//
//  Sum of matrices
//  C = A + B;
//
//  Dif of matrices
//  C = A - B;

In addition, the Matrix class implements to function q_to_mat. This method of the Matrix class operates on objects of the class Quaternion, defined in the next section.

3.0 Quaternion

A quaternion is an object consisting of four scalar numbers. If a quaternion has the property that it has a magnitude of 1, it is called a "versor." Versors are generally used to represent rotations of a rigid body. In aerospace navigation, Versors are sometimes used for this purpose, but the usual practice is to call them quaternions instead of versors, which are a special type of quaternion.

The quaternion consists of four scalar values, (s,v1,v2,v3). The magnitude of a quaternion is sqrt(s*s+v1*v1+v2*v2+v3*v3). At present, no algebra of quaternions has been implemented in the Quaternion class, but the Matrix class has a method to convert a quaternion to a matrix.

Example

Quaternion qbi;
Matrix tr_inertial_to_body;
tr_inertial_to_body = tr_inertial_to_body.q_to_mat(qbi);

All you will need to use the linear module are files linear.h and linear.cpp.

Go Back