Skip to content
Justin edited this page Mar 10, 2022 · 3 revisions

CGAL uses Eigen for many of its algorithm and CGALDotNet provides a Eigen matrix and vector classes to work with.

You can check the Eigen version as follows.

//Print the Eigen version.
Console.WriteLine("The Eigen Version in use is " + CGALGlobal.EigenVersion);

Some basic matrix math can be performed as followed.

//Create a 4 x 4 translation matrix.
var m = EigenMatrix.Translate(new Point3d(1, 2, 3));

//Create a vector.
var v = new EigenColumnVector(0, 0, 0, 1);

//Transform vector.
v = v * m;

A linear systems can be solved as follows.

Eigen provides a range of methods to use for linear systems and more information can be found here.


//Create a matrix by setting the rows.
var A = new EigenMatrix(3, 3);
A.SetRow(0, 1, 2, 3);
A.SetRow(1, 4, 5, 6);
A.SetRow(2, 7, 8, 10);

//Creaye the vector to solve.
var b = new EigenColumnVector(3, 3, 4);

//Solve the linear system using the ColPivHouseholderQr method.
var x = A.ColPivHouseholderQr(b1);

And finally the eigen values and vectors can be found as follows.


//Create a matrix.
var m = new EigenMatrix(1, 2, 2, 3);

//Try and find the matrices eigen values and vector.
if (m.EigenValuesAndVectors(out EigenColumnVector values, out EigenMatrix vectors))
{
    //The eigen values and vector have been found.
    values.Print();
    vectors.Print();
}
else
{
    //Failed to find eigen values and vectors
}

Clone this wiki locally