Seite 1 von 3
3D - Rotation
Verfasst: 20.01.2008 17:58
von Andreas_S
Ich habe hier für jede Ache eine Rotations-Gleichung gemacht:
Code: Alles auswählen
// X Rotation
result.x = point.x;
result.y = rotatePoint.y + (cos(rotateAngle.x) * d.y - sin(rotateAngle.x) * d.z);
result.z = rotatePoint.z + (sin(rotateAngle.x) * d.y + cos(rotateAngle.x) * d.z);
// Y Rotation
result.x = rotatePoint.x + (cos(rotateAngle.y) * d.x - sin(rotateAngle.y) * d.z);
result.y = point.y;
result.z = rotatePoint.z + (sin(rotateAngle.y) * d.x + cos(rotateAngle.y) * d.z);
// Z Rotation
result.x = rotatePoint.x + (cos(rotateAngle.z) * d.x - sin(rotateAngle.z) * d.y);
result.y = rotatePoint.y + (sin(rotateAngle.z) * d.x + cos(rotateAngle.z) * d.y);
result.z = point.z;
Und jetzt will ich die Gleichungen zusammenfügen...
Nur hab ich das nicht ganz hinbekommen:
Code: Alles auswählen
// X + Y + Z Rotation
result.x = rotatePoint.x + (cos(rotateAngle.y) * cos(rotateAngle.z) * d.x - sin(rotateAngle.z) * d.y - sin(rotateAngle.y) * d.z);
result.y = rotatePoint.y + (sin(rotateAngle.z) * d.x + cos(rotateAngle.z) * cos(rotateAngle.x) * d.y - sin(rotateAngle.x) * d.z);
result.z = rotatePoint.z + (sin(rotateAngle.y) * d.x + cos(rotateAngle.y) * cos(rotateAngle.x) * d.z + sin(rotateAngle.x) * d.y);
Danke voraus,
Andreas
Verfasst: 20.01.2008 18:53
von Andreas_S
Kann mir da keiner helfen? ...
Verfasst: 20.01.2008 19:31
von hardfalcon
Das hier ist weder ein Chat noch eine 24/7-Supporthotline, sondern ein Forum.
Durchaus möglich, dass du ein paar Stunden oder Tage auf ne Antwort warten musst.
Geduld, gut Ding will Weile haben!

Verfasst: 20.01.2008 19:59
von Andreas_S
Wollte nur rasch meinen Code weiterschreiben und war ein bischen ungeduldig...
Sorry
Verfasst: 21.01.2008 15:42
von Scarabol
1 Stunde
Kein Wunder das du keine Antwort bekommst
Wieso lässt du den Code nicht einfach in 3 Formeln aufgeteilt?
Ansonsten kann ich dir empfehlen, die Schreibweise zu vereinfachen und cos(rotateanglex) einfach durch a sin(rotateangle) durch b usw zu erstzen, dann ist es am Ende ganz einfach die übersichtlicheren Buchstaben zu ordnen und zusammenzufügen...
Eine Beschreibung (Skizze) was die Bezeichnungen im einzelnen Bedeuten währ auch nicht schlecht....
Gruß
Scarabol
Verfasst: 21.01.2008 21:30
von Andreas_S
sorry... hatte vergessen die Variablen und den Sinn dieser Gleichungen zu erklären...
// X Rotation
result.x = point.x;
result.y = rotatePoint.y + (cos(rotateAngle.x) * d.y - sin(rotateAngle.x) * d.z);
result.z = rotatePoint.z + (sin(rotateAngle.x) * d.y + cos(rotateAngle.x) * d.z);
// Y Rotation
result.x = rotatePoint.x + (cos(rotateAngle.y) * d.x - sin(rotateAngle.y) * d.z);
result.y = point.y;
result.z = rotatePoint.z + (sin(rotateAngle.y) * d.x + cos(rotateAngle.y) * d.z);
// Z Rotation
result.x = rotatePoint.x + (cos(rotateAngle.z) * d.x - sin(rotateAngle.z) * d.y);
result.y = rotatePoint.y + (sin(rotateAngle.z) * d.x + cos(rotateAngle.z) * d.y);
result.z = point.z;
Ich habe einen Punkt irgendwo in einem Koordinatensystem. Dann hab ich noch einen Rotationsmittelpunkt der auch irgendwo im Koordinatensystem ist.
Jetzt will ich den Punkt um den Rotationspunkt drehen, und hab mir überlegt wie das gehn könnte. Ich habe bemerkt das die Formel "neuX = cos(Winkel) * y - sin(Winkel) * x" nur funktioniert wenn x und y der abstand zum Nullpunkt ist.
So hab ich einfach die absolute Position des Rotationspunktes von der absoluten Position des Punktes abgezogen. So bekomm ich das gewollte system un muss schussendlich nur noch die Position des Rotationspunktes dazuzählen...
Die Variablen:
result. -> neue absolute Position des rotierten Punktest
d.x -> der relative Abstand des absoluten Punktes vom absoluten rotations Punktes
rotatePoint. -> die absolute Position des rotations Mittelpunktes
rotateAngle. -> der Winkel von der anfangs Position ( -> d. ) zur neuen Position
//edit
Warum ich nicht die drei Formeln aufgespalten lassen soll? Das ist doch klar
Weil ich eine zusammenhängende Rotation will... Es bringt ja nicht viel wenn ich nur eine Achse rotieren kann, ich will ja alle gleichzeitig rotieren...
Verfasst: 22.01.2008 00:16
von NicTheQuick
Im 3D-Raum musst du nur 2 Achsen drehen um einen Punkt zu rotieren. Im
2D-Raum brauchst du ja auch nur einen Winkel. Im nD-Raum braucht man
(n-1) Winkel um einen Punkt zu rotieren.
Deinen Kopf bewegst du ja auch nur nach links und rechts und nach oben und
nach unten. Wenn du ihn schief hälst, nennt man das zwar umgangssprachlich die Z-Achse, ist aber in Wirklichkeit nur die Drehung um die Achse, die du vorher mit der X- und Y-Achse positioniert hast.
Sozusagen drehst du deinen Kopf auf der X- und Y-Achse und die Z-Rotation
ist dann die um deine Nase.

Verfasst: 27.01.2008 12:03
von Scarabol
Hi,
kannst du die Gleichungen nicht einfach addieren?
Also so:
result.x = point.x rotatePoint.x + (cos(rotateAngle.y) * d.x - sin(rotateAngle.y) * d.z) rotatePoint.x + (cos(rotateAngle.z) * d.x - sin(rotateAngle.z) * d.y)
Gruß
Scarabol
Verfasst: 27.01.2008 14:03
von Deeem2031
Also in meinem uralten version ein Software 3D-Renderer zu basteln sah das so aus:
Code: Alles auswählen
xx.f = _Cos(wy) * _cos(wz) * x1 - _cos(wy) * _sin(wz) * y1 + _sin(wy) * z1
yy.f = (_cos(wx) * _sin(wz) + _sin(wx) * _sin(wy) * _cos(wz)) * x1 + (_cos(wx) * _cos(wz) - _sin(wx) * _sin(wy) * _sin(wz)) * y1 - _sin(wx) * _cos(wy) * z1
zz.f = (_sin(wx) * _sin(wz) - _cos(wx) * _sin(wy) * _cos(wz)) * x1 + (_sin(wx) * _cos(wz) + _cos(wx) * _sin(wy) * _sin(wz)) * y1 + _cos(wx) * _cos(wy) * z1
Allerdings kann ich mich daran erinnern, das ich die Formeln nicht selber geschrieben hab, sondern irgendwo im Inet gefunden hatte. Kann dir also leider nicht sagen, wie man darauf kommt.
Verfasst: 27.01.2008 14:34
von Scarabol
Kannst du noch etwas näher erläutern wofür die einzelnen Variabeln stehen?
Vor allem wieso die Winkelfunktionen einen Unterstrich haben?
Sind die x1, y1, z1 Werte die Ursprungspunkte?
Gruß
Scarabol