PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Matrizen und Koordinatensysteme


Gast
2013-04-15, 09:46:39
Hallo,
es geht um die Verschiebung von Vektoren von einem World Koordinatensystem in ein Objectspacekoordinatensystem. Dummerweise kann ich mit Matrizenrechnung so garnix anfangen.

Laut meinem Tutorial (http://jerome.jouvie.free.fr/opengl-tutorials/Tutorial26.php) sieht die Formel dafür so aus:

[Rx]T = | 1 0 0 |T = | 1 0 0 |
T | 0 cosθ sinθ |T | 0 cosθ -sinθ |
T | 0 -sinθ cosθ |T | 0 sinθ cosθ |

Similarly :
[Ry]T = | cosθ 0 -sinθ |T = | cosθ 0 sinθ |
T | 0 1 0 |T | 0 1 0 |
T | sinθ 0 cosθ |T | -sinθ 0 cosθ |
[Rz]T = | cosθ sinθ 0 |T = | cosθ -sinθ 0 |
T | -sinθ cosθ 0 |T | sinθ cosθ 0 |
T | 0 0 1 |T | 0 0 1 |


Und hier die Funktion aus dem Tutorial, dort fehlt die Umrechnung für die Z Rotation:

public Vector toVectorInFixedSystem1(float dx, float dy, float dz)
{
//Don't calculate for nothing ...
if(dx == 0.0f & dy == 0.0f && dz == 0.0f)
return new Vector();

//Convert to Radian : 360° = 2PI
double xRot = Math.toRadians(position.x); //Math.toRadians is toRadians in Java 1.5 (static import)
double yRot = Math.toRadians(position.y);

//Calculate the formula
float x = (float)( dx*Math.cos(yRot) + dy*Math.sin(xRot)*Math.sin(yRot) - dz*Math.cos(xRot)*Math.sin(yRot) );
float y = (float)( + dy*Math.cos(xRot) + dz*Math.sin(xRot) );
float z = (float)( dx*Math.sin(yRot) - dy*Math.sin(xRot)*Math.cos(yRot) + dz*Math.cos(xRot)*Math.cos(yRot) );
return new Vector(x, y, z);
}


Wie kann ich nun diese Formel umsetzen damit ich Z-Rotation einbauen kann?

Gast
2013-04-16, 08:38:23
Matrixmultiplikation: http://en.wikipedia.org/wiki/Matrix_multiplication#Matrix_product_.28two_matrices.29

Rotationsmatrizen: http://en.wikipedia.org/wiki/Rotation_matrix#In_three_dimensions

Wenn du die Matrizen für x und y Rotation zusammenmultiplizierst erhältst du eine gesamte Transformationsmatrix für x und y Rotation, das ist das was deine Funktion anscheinend macht. Wenn du alle 3 Matrizen zusammenmultiplizierst erhältst du eine Transfomrationsmatrix für Rotation um alle 3 Achsen, das ist das was du willst.

Und noch ein guter Tipp: "Dummerweise kann ich mit Matrizenrechnung so garnix anfangen." solltest du schnell ändern wenn du vorhast in dem Bereich irgendwas sinnvolles zu programmieren. Ohne grundlegende Lineare Algebra Kenntnisse gehts einfach nicht :)