Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/w1th0utnam3/linear_algebra_containers
Some basic, c++ template linear algebra classes (vector, matrix, quaternion) useful for computer graphics or other computations.
https://github.com/w1th0utnam3/linear_algebra_containers
linear-algebra matrix quaternion
Last synced: 9 days ago
JSON representation
Some basic, c++ template linear algebra classes (vector, matrix, quaternion) useful for computer graphics or other computations.
- Host: GitHub
- URL: https://github.com/w1th0utnam3/linear_algebra_containers
- Owner: w1th0utnam3
- License: mit
- Created: 2015-07-08T15:48:19.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-09-13T19:50:06.000Z (over 8 years ago)
- Last Synced: 2024-12-19T05:48:36.106Z (15 days ago)
- Topics: linear-algebra, matrix, quaternion
- Language: C++
- Size: 71.3 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# linear_algebra_containers
Some basic, c++ template linear algebra classes (vector, matrix, quaternion)
useful for non high performance calculations (the classes don't use template
expressions, unrolling or other optimizations).All files of this project are licensed under the MIT license. Have a look
at the LICENSE file for more information.## Overview
Classes already implemented:
- `Matrix`: m x n matrix with entries of type T
- `ColumnVector`: column vector with n entries of type T
- `Vector3`: column vector with 3 entries of type T
- `Quaternion`: class for rotations etc., with 4 entries of type TAll classes are using templates. For example the `Matrix` template parameters
are:
```c++
template
class Matrix;
```
The `ColumnVector` is a partial specialization of the corresponding matrix type
while the Vector3 class is a subclass of the ColumnVector.## Examples
Matrix operations are very easy to use and thanks to the template design only
mathematically correct operations are possible. Example for a matrix product:
```c++
lin_algebra::Matrix mat1; mat1.toIdentity();
lin_algebra::Matrix mat2; mat2.toIdentity();
lin_algebra::Matrix result = mat1*mat2;
```
The multiplication in reverse order will not work because the matrix dimensions
do not match.
```c++
auto result = mat2*mat1; // Won't compile
```
Suppose you want to calculate the 2-norm of a column vector. There are three
ways to get the same result:
```c++
typedef lin_algebra::ColumnVector vec4;
typedef lin_algebra::Matrix mat4x1;vec4 x{1.,2.,3.,4.};
mat4x1 y{1.,2.,3.,4.};double res1 = std::sqrt(x.transposed()*x); // 1
double res2 = std::sqrt(vec4::dotProduct(x,x)); // 2
double res3 = y.norm(); // 3
assert(res1 == res2);
assert(res2 == res3);
```
`ColumnVector` is just an alias for `Matrix` so it's not surprising
that everything above works. Additionally the partial specialization allows the
following to work:
```c++
typedef lin_algebra::Matrix mat4x4;mat4x4 eye;
eye.toIdentity();
vec4 empty{0;0;0;0};double res4 = (M*x + empty).norm();
assert(res4 == res1);
```## Todo
There is still much work to do on the classes even though most basic operations
are working. If you want to help or if you find any bugs feel free to contact
me.Main areas of work:
- More quaternion methods
- More tests
- Matrix4x4 and Matrix3x3 classes with convenience methods
- More graphics related features like rotations etc.
- Point classes & coordinate system transformations