如何对列表列表的列表执行矩阵变换函数#
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 2 的 Square 6 等的角点。矩阵变换是我想要在我的列表上做的。
我正在尝试这样做,但因为这不是一个普通数组,而是一个列表列表。我没有访问或设置正确的值 way.I 得到超出范围的数组范围错误。有没有更好的方法来实现我想要做的事情?
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;
}
我有一个 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 2 的 Square 6 等的角点。矩阵变换是我想要在我的列表上做的。
我正在尝试这样做,但因为这不是一个普通数组,而是一个列表列表。我没有访问或设置正确的值 way.I 得到超出范围的数组范围错误。有没有更好的方法来实现我想要做的事情?
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;
}