2017-03-02 1 views
0

Ich habe eine Liste von Listen des Typs MCvPoint3D32f. Ein MCvPoint3D32f-Punkt ist ein 3D-Punkt vom EmguCV-Typ, der (x, y, z) Gleitkommawerte enthält. Diese Liste speichert 4 Eckpunkte eines Quadrats. Z.B. Platz 0 hat 4 Eckpunkte Platz [0] [0], Platz [0] [1.] .. Platz [0] [3] usw.Wie eine Matrix-Transformationsfunktion auf einer Liste von Listen durchführen C#

Die Reihenfolge der gespeicherten Ecken stimmt nicht mit der Reihenfolge überein Ich will. Zum Beispiel enthalten die Eckpunkte, die in dem Quadrat 1 gespeichert sind, Eckpunkte von Quadrat 3, Quadrat 2 von Quadrat 6 usw. Eine Matrixtransformation ist, was ich auf meiner Liste tun möchte.

Ich versuche das zu tun, aber da dies kein normales Array ist, sondern eine Liste von Listen. Ich greife nicht auf die Werte zu oder setze sie nicht korrekt. Ich bekomme einen Array-Bereichsfehler außerhalb der Grenzen. Gibt es einen besseren Weg, um das zu erreichen, was ich versuche?

The matrix

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]; 
      } 
     } 
    } 
+1

Nicht http://stackoverflow.com/questions/6950495/linq-swap-columns-into-rows Ihre Frage beantworten? – rkrahl

+0

Ich denke nicht. Ich verstehe nicht einmal, was dieser Code macht. Aber ich möchte die inneren Elemente meiner Quadrate tauschen. dh. die 4 Eckpunkte in Square [1] bis Square [3] usw. gespeichert –

+0

Grundsätzlich möchte ich die inneren Elemente tauschen –

Antwort

0

Dies kann nicht der beste Ansatz sein, das obige Problem zu lösen, da es ist ziemlich viel für 3x3-Matrix hartcodiert, sondern arbeitet für jetzt.

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; 
    } 
Verwandte Themen