Hi,
ich habe ein mathematisches Problem. Ich möchte mit PHP einen Würfel in 3D Ansicht zeichnen und diesen anhand von Winkelangaben drehen können. Mein Problem ist nun, wie dreht man einen Würfel? Das mit den zeichnen ist kein Problem (Funktioniert auf jeden fall) aber ich habe keine Ahnung, wie man ihn dreht.
Ich habe schon gegooglet und in eine Formelsammlung geguckt und nichts Richtiges gefunden.
Das einzige war das: Drehung (Rotation) eines kartesischen Koordinatensystems um den Winkel w
Daraus hab ich folgendes gemacht, wobei ich z mir selbst ausgedacht habe.
PHP-Code:
// Berechnungen zum drehen
// 1. Punbkt
$x1g = $x1 * cos($wx) + $y1 * sin($wx);
$y1g = -$x1 * sin($wy) + $y1 * cos($wy);
$z1g = $z1 * cos($wz) + $z1 * sin($wz);
// 2. Punbkt
$x2g = $x2 * cos($wx) + $y2 * sin($wx);
$y2g = -$x2 * sin($wy) + $y2 * cos($wy);
$z2g = $z2 * cos($wz) + $z2 * sin($wz);
// 3. Punbkt
$x3g = $x3 * cos($wx) + $y3 * sin($wx);
$y3g = -$x3 * sin($wy) + $y3 * cos($wy);
$z3g = $z3 * cos($wz) + $z3 * sin($wz);
// 4. Punbkt
$x4g = $x4 * cos($wx) + $y4 * sin($wx);
$y4g = -$x4 * sin($wy) + $y4 * cos($wy);
$z4g = $z4 * cos($wz) + $z4 * sin($wz);
// 5. Punbkt
$x5g = $x5 * cos($wx) + $y5 * sin($wx);
$y5g = -$x5 * sin($wy) + $y5 * cos($wy);
$z5g = $z5 * cos($wz) + $z5 * sin($wz);
// 6. Punbkt
$x6g = $x6 * cos($wx) + $y6 * sin($wx);
$y6g = -$x6 * sin($wy) + $y6 * cos($wy);
$z6g = $z6 * cos($wz) + $z6 * sin($wz);
// 7. Punbkt
$x7g = $x7 * cos($wx) + $y7 * sin($wx);
$y7g = -$x7 * sin($wy) + $y7 * cos($wy);
$z7g = $z7 * cos($wz) + $z7 * sin($wz);
// 8. Punbkt
$x8g = $x8 * cos($wx) + $y8 * sin($wx);
$y8g = -$x8 * sin($wy) + $y8 * cos($wy);
$z8g = $z8 * cos($w) + $z8 * sin($w);
So, jetzt die Frage:
Bin ich auf den richtigen Weg oder ist alles totaler Unsinn?
Muss der Winkel immer der Gleiche sein oder gibt es für jede Achse einen anderen? (Denke schon)
PS. das hab ich im netz gefunden weiss aber nicht so recht damit etwas anzufangen:
PHP-Code:
/*Um die x-Achse: Die entsprechende Matrix:
x´ = x 1 0 0
y´ = y * cos (a) - z * sin (a) 0 cos (a) - sin (a)
z´ = y * sin (a) + z * cos (a) 0 sin (a) cos (a)
Um die y-Achse: Die entsprechende Matrix:
x´ = x * cos (a) + z * sin (a) cos (a) 0 sin (a)
y´ = y 0 1 0
z´ = - x * sin (a) + z * cos (a) - sin (a) 0 cos (a)
Um die z-Achse: Die entsprechende Matrix:
x´ = x * cos (a) - y * sin (a) cos (a) - sin (a) 0
y´ = x * sin (a) + y * cos (a) sin (a) cos (a) 0
z´ = z 0 0 1
*/
zum angucken:
PHP 3D
Thx schon mal für die antworten
MfG Flyscorpion