user236520
user236520

Reputation:

C# math libraries that operate on simple vectors and arrays

There are several math libraries for c#, but they all seem to either define their own vector and matrix types, or operate on established c# classes like Vector3D or Vector.

Are there any math libraries that operate on "simple" vector and matrix types such as double[] and double[,]

Some example of "nice to have" functions would be

double[] v = new double[3];
double[] w = new double[3];
double m[,] = new double[3,3];

double vDOTv = DesiredClass.Dot(v); // v.v

double[] normV = DesiredClass.Normalize(v); // normalize vector

double[] cCROSSw = DesiredClass.Cross(v,w);  // v x w

double vDOTm = DesiredClass.Dot(v,m,i); // v.m[i] - dot product of v with ith row of m

Upvotes: 4

Views: 3724

Answers (2)

Matt Ellen
Matt Ellen

Reputation: 11602

Math.Net Numerics provides various matrix methods including MatrixMultiply and MatrixNorm, that work on double[], so it looks like it does most of what you need. I couldn't see the dot product, but it might be under a different name I'm unaware of.

Upvotes: 1

Marino Šimić
Marino Šimić

Reputation: 7342

You could create your own classes for these types and provide them with implicit conversion from and to double arrays, then create those utility methods accepting parameters of your own type that would work on those arrays since there is an implicit conversion.

But that would be a bit fishy, why not work on normal types already.

Upvotes: 1

Related Questions