Cross Product Using Math.Net Numerics With C#


Answer :

Sample method to do the cross-product of a 3 element vector.



    using DLA = MathNet.Numerics.LinearAlgebra.Double;

public static DLA.Vector Cross(DLA.Vector left, DLA.Vector right)
{
if ((left.Count != 3 || right.Count != 3))
{
string message = "Vectors must have a length of 3.";
throw new Exception(message);
}
DLA.Vector result = new DLA.DenseVector(3);
result[0] = left[1] * right[2] - left[2] * right[1];
result[1] = -left[0] * right[2] + left[2] * right[0];
result[2] = left[0] * right[1] - left[1] * right[0];

return result;
}


You are accessing the API documentation for Math.NET Iridium, which is a discontinued project. The intention was that the Iridium code base should be integrated into Math.NET Numerics, but it seems that the CrossProduct functionality has not been transferred yet, as can be seen in these two discussion threads on the Math.NET Numerics Codeplex site.



If you want to use Math.NET Iridium, where the CrossProduct method is surely available, you can download the most recent source code from here.



Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable