0

编辑:
修复语法错误并使用此算法后,我发现 MKL 提供程序不是所需的矩阵乘法。该算法只是将元素乘以元素,而不是dot(row_n,column_n)像我最初想象的那样计算 。

其他来源

结束编辑

我无法通过编译器。我到处寻找一个很好的例子,但都没有找到。我引用的文档是MklLinearAlgebraProvider

MathNet.Numerics.Algorithms.LinearAlgebra.Mkl.MklLinearAlgebraProvider

我正在尝试编写一个简单的方法来计算R = rz*ry*rx欧拉角的旋转矩阵。问题是编译器不会接受ryXrx或者resultMat我试图传递它的数组。我也尝试过out关键字。

inputMat是 {x,y,z,rx,ry,rz} 形式的一维数组,其中 x,y 和 z 是平移,rx,ry 和 rz 是以度为单位的旋转角度。

 private float[,] EulerToHMat(float[] inputMat)
    {
        var linalg = new MathNet.Numerics.Algorithms.LinearAlgebra.Mkl.MklLinearAlgebraProvider();

        double rzRad = ((double)inputMat[5])*Math.PI/180;
        double cosZ = Math.Cos(rzRad);
        double sinZ = Math.Sin(rzRad);

        double ryRad = ((double)inputMat[4])*Math.PI/180;
        double cosY= Math.Cos(ryRad);
        double sinY = Math.Sin(ryRad);

        double rxRad = ((double)inputMat[3])*Math.PI/180;
        double cosX= Math.Cos(rxRad);
        double sinX = Math.Sin(rxRad);



        var rz = new float[,] { { (float)cosZ, -(float)sinZ, 0 }, { (float)sinZ, (float)cosZ , 0 }, {0,0,1 } };

        var ry = new float[,] { { (float)cosY , 0 , (float)sinY }, { 0, 1 , 0 }, { -(float)sinY, 0, (float)cosY } };

        var rx = new float[,] { {1,0,0 }, {0,(float)cosX,-(float)sinX }, {0,(float)sinX,(float)cosX } };


        var ryXrx = new float[3,3];  
        var resultMat = new float[3, 3];

        // won't take the matrix --ryXrx-- here 
        linalg.MatrixMultiply(ry, 3, 3, rx, 3, 3,ryXrx);  

        // won't take the matrix --resultMat-- here 
        linalg.MatrixMultiply(rz, 3, 3, ryXrx, 3, 3,resultMat);


        return resultMat;

    }

这看起来应该很简单......请忽略铸造混乱。

4

1 回答 1

1

根据您链接的参考资料,该方法适用于存储在单维数组中的矩阵,您正在尝试传递二维。

试试这个:

var rz = new float[] {  (float)cosZ, -(float)sinZ, 0, (float)sinZ, (float)cosZ, 0, 0, 0, 1  };

var ry = new float[] {  (float)cosY, 0, (float)sinY,  0, 1, 0, -(float)sinY, 0, (float)cosY };

var rx = new float[] { 1, 0, 0, 0, (float)cosX, -(float)sinX, 0, (float)sinX, (float)cosX };

int size = 3;
var ryXrx = new float[size * size];  
var resultMat = new float[size * size];

// won't take the matrix --ryXrx-- here 
linalg.MatrixMultiply(ry, size, size, rx, size, size,ryXrx);  
于 2013-12-26T23:36:45.837 回答