繁体   English   中英

如何在列表列表上执行矩阵变换功能C#

[英]How to perform a matrix transform function on a lists of lists c#

我有一个MCvPoint3D32f类型的列表列表。 MCvPoint3D32f点是包含(x,y,z)浮点值的EmguCV类型3D点。 此列表存储一个正方形的4个角点。 例如Square 0将具有4个角点Square [0] [0],Square [0] [1 .... Square [0] [3]等。

存储的角的顺序与我想要的顺序不一致。 例如,存储在Square 1中的角点包含Square 3的角点,Square 6的Square 2的角点等。矩阵转换是我要在列表中执行的操作。

我正在尝试这样做,但是由于这不是普通数组而是列表列表。 我没有以正确的方式访问或设置值。我得到了超出范围的数组范围错误。 有没有更好的方法来实现我想要做的事情?

矩阵

 List<List<MCvPoint3D32f>> tempList = new List<List<MCvPoint3D32f>>();
 SortMatrixIndex(Matrix);
 private void SortMatrixIndex(List<List<MCvPoint3D32f>> matrix)
 {
     for (int i = 0; i < matrix.Count; i++)
        {
          if (i == 0 || i == 3 || i == 4 || i == 8)
           {
                tempList[i] = matrix[i];
           }
          else if (i == 5)
          {
                tempList[i] = matrix[i];
                matrix[i] = matrix[i + 2];
                matrix[i + 2] = tempList[i];
          }
          else
          {
                tempList[i] = matrix[i];
                matrix[i] = matrix[i * 3];
                matrix[i * 3] = tempList[i];
          }
      }
  }

这可能不是解决上述问题的最佳方法,因为它对于3x3矩阵几乎是硬编码的,但现在可以使用。

 private void TransposeMatrix(List<List<MCvPoint3D32f>> matrix)
 {
     //This case applies to both N and W, however N needs column swapping too
     for (int i = 0; i < matrix.Count; i++)
       {
          tempList.Add(new List<MCvPoint3D32f>());

           if (i == 1 || i == 2)
           {
               tempList[i] = matrix[i];
               matrix[i] = matrix[i * 3];
               matrix[i * 3] = tempList[i];   
           }
           else if (i == 5)
           {
               tempList[i] = matrix[i];
               matrix[i] = matrix[i + 2];
               matrix[i + 2] = tempList[i];
           }
           else
           {
               tempList[i] = matrix[i];
           }
        }

        tempList.Clear();
        this.squareMatt = matrix;
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM