Project Description
A generic linear algebra toolkit in C# Compatible with Silverlight.
This library provides basic linear algebra routines for the .NET platform. It is a generic library designed to work with any numeric type (float, double, ...)
- 2d vectors
- 3d vectors
- 3x3 matrices
- 4x4 matrices
- Lines
- Planes
Matrices
//Declare a 3x3 matrix
Matrix33<double> m33 = new Matrix33<double>(6, -7, 10, 0, 3, -1, 0, 5, -7);
//Get the inverse
Matrix33<double> m33Inv = m33.Inverse();
//Multiply the matrix by it's inverse
Matrix33<double> result = m33 * m33Inv;
//Prints true if result equals the 4x4 identity matrix
Console.WriteLine(result == Matrix33<double>.Identity()); //True
Vectors
//Declare two unit vectors e1, e2
Vec3<int> e1 = new Vec3<int>(1, 0, 0);
Vec3<int> e2 = new Vec3<int>(0, 1, 0);
//Calculate the dot-product :
int proj = e1 ^ e2;
//Check if proj == 0
Console.WriteLine(proj == 0); //True
//Calculate the cross product
Vec3<int> e3 = e1 % e2;
Vec3<int> e4 = new Vec3<int>(0, 0, 1);
//Check if e3 == (0, 0, 1)
Console.WriteLine(e3 == e4); //True
Version 1.6
Version 1.6 has more relaxed type constraints. It works with numeric types such as complex and BigInteger.
Complex Matrices:
In order to use complex and BigInteger class you must refernece the System.Numerics assembly.
var i = Complex.ImaginaryOne;
//Declare a 4x4 matrix
Matrix44<Complex> m44 = new Matrix44<Complex>(1, 1, 1, 1, 1, i, -1, -i, 1, -i, 1, -1, 1, -i, -1, i);
//Declare an identity matrix
//We must provide the multiplicative identity
//for complex numbers.
Matrix44<Complex> id = Matrix44<Complex>.Identity(1.0);
Console.WriteLine(id * m44 == m44);//true