The CwMtx library for matrix, vector and quaternion math

CwMtx is a library I wrote in C++ that provides the matrix and vector operations that are used extensively in engineering and science problems.

A special feature of this library is the quaternion class which implements quaternion math. Quaternions are very useful for attitude determination in 3D space because they do not suffer from singularities. Furthermore, successive rotations and transformations of vectors can be accomplished by simple quaternion multiplication. Attitude dynamics can be expressed in a very compact form using quaternions.

For more information on quaternions and their applications, see: "Spacecraft attitude determination and control", Edited by James Wertz, D. Reidel Publishing Company, Dordrecht: Holland, Boston: U.S.A., London: England.

Speeding up CwMtx

The original version of CwMtx contains matrices that can be dimensioned dynamically. This is very flexible but it also slows matrix operations down because dynamic memory management is slow. In an attempt to circumvent this disadvantage I created a version of CwMtx that contains statically dimensioned matrices. This speeds up matrix operations considerably. Especially operations on small matrices (3x3, 4x4) and vectors (3x1, 4x1) as used in 3D problems are 3 to 5 times faster than with their dynamically dimensioned counterparts. However, I think CwMtx is not the fastest matrix library around and speed is not the highest priority for me.


If you want to try CwMtx download it using one of the links below. CwMtx is licensed under the Lesser GPL (LGPL). It is written entirely in C++. It was developed on Linux using the C++ compiler from the GNU Compiler Collection but you should be able to use it on any system that has a recent C++-compiler.

Please read this first:
Some browsers automatically uncompress .tar.gz archives if you download them by left-clicking (I know IE does this). However they do not remove the .gz extension from the filename causing all kinds of confusion. To prevent this: right-click on the link and choose "Save Link as ..." or something similar from the menu that pups up.

The latest version of the CwMtx library for dynamically dimensioned matrices is:

The latest version of the CwMtx library for statically dimensioned matrices is:

IMPORTANT for CwMtx version >= 0.6.0

As of version 0.6.0 all function names within the CwMtx namespace have been changed to start with a lowercase letter. (Sorry for the inconvenience but I decided to apply a single name convention to all my software). You can use the sed script linked here to rename functions to start with a lowercase letter. Some manual checking is required after applying the script though.


I ran Doxygen on the raw sources, use these links to view the results.

If you want to read the full documentation in text format, use these links. The documents can be slightly out of date but they are useable.

If I can find the time I wil integrate the documentation text file with the sources to produce a good documentation set using Doxygen.


This software was converted from a classic object code library to a template library by William DeVore. Jiri Ecer added some extra constructors that create a quaternion from its exponential form q = r * e^(n_hat * theta), where n_hat is a unit vector.

The strength of the templates are that you can use them to generate unusual types of matrices and vectors, like a matrix of quaternions, a vector of square matrices, etc. Nevertheless these unusual datatypes can be very useful for some particular problems. (Please, let me know if you generated some weird-but-useful datatypes with the CwMtx templates.)

Other Scientific and Engineering software


If you have any questions or remarks on CwMtx, please let me know.

Harry Kuiper (hkuiper at xs4all dot nl)