7

I have two vectors MathNet.Numerics.LinearAlgebra.Generic.Vector<double>, like the following:

Vector<double> v1 = new DenseVector(new double[] { 1, 2, 3 });     
Vector<double> v2 = new DenseVector(new double[] { 3, 2, 1 });

I basicly want to CrossProduct them, however couldn't find an official function. I know cross product is a very easy function which I can write myself, but I want to use the API's function.

Both of the below works for me: (Couldn't find such functions in the API.)

Vector<double> result = v1.CrossProduct(v2);
Vector<double> result = Vector.CrossProduct(v1,v2);

I found this, however couldn't find the function when I tried to write it: API Reference

TylerH
  • 20,799
  • 66
  • 75
  • 101
Sait
  • 19,045
  • 18
  • 72
  • 99
  • Are you sure you have the same version of the library that the docs were built from? – Jon Skeet Aug 01 '12 at 12:56
  • I'm not entirely sure what you're saying. Are you saying you're not sure, or that you *don't* think it's a good question? – Jon Skeet Aug 01 '12 at 13:04
  • @JonSkeet: Sorry. I was checking my version and docs version. I'm not sure my math.net numerics's version yet. I'm checking it. Thanks. – Sait Aug 01 '12 at 13:10
  • 1
    Wierd. A massive library of numerical functions yet the very basic cross product is missing?? – bradgonesurfing Jan 03 '13 at 15:11

2 Answers2

7

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;
    }
denver
  • 2,863
  • 2
  • 31
  • 45
3

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.

Anders Gustafsson
  • 15,837
  • 8
  • 56
  • 114
  • Hmmm, I see. Do you think switching back to Iridium is a good idea? – Sait Aug 01 '12 at 13:23
  • @zagy I have updated my answer with some confirmations that the _Numerics_ library does not yet contain `CrossProduct`. If you can consider writing your own `CrossProduct` method, it is probably better to stick with the _Numerics_ library in the long run, since it is still actively developed. – Anders Gustafsson Aug 01 '12 at 13:39
  • 'activley' but still missing that function ... although this is an interesting read maybe explaining why http://www.gamedev.net/topic/181474-4-dimensional-crossproduct/ – John Nicholas May 16 '14 at 22:21
  • 1
    By now the method ```Vector3.Cross()``` exists. – H. de Jonge Aug 26 '23 at 10:24