Problem: 
Gegeben sind die Koordinaten eines Objekts (x/y/z) in VRML. Dieses Objekt soll nun immer in die Richtung eines bestimmten Punktes ausgerichtet werden. Z.B. dem Punkt (0/0/0).
Mein Lösungsansatz mit PHP:
Zunächst wird die Euler- Rotation anhand der Koordinaten berechnet.
Und zwar eine nach der anderen:
Info: Punkt: ($y/$y/$Z), rotation: $xr, $yr, $zr
 
	
Dann erfolgt die Umwandlung in ein Quaternion: 
 
	
So, irgendwas stimmt da nicht. Obwohl es schon nicht schlecht aussieht. 
Hab ich einen Denkfehler???
bin mal gespannt ob mir da jemand helfen kann...
Stefan
					Gegeben sind die Koordinaten eines Objekts (x/y/z) in VRML. Dieses Objekt soll nun immer in die Richtung eines bestimmten Punktes ausgerichtet werden. Z.B. dem Punkt (0/0/0).
Mein Lösungsansatz mit PHP:
Zunächst wird die Euler- Rotation anhand der Koordinaten berechnet.
Und zwar eine nach der anderen:
Info: Punkt: ($y/$y/$Z), rotation: $xr, $yr, $zr
PHP-Code:
	
	
// Y- ROTATION 
if (($z == 0) && ($x >= 0)) { 
$yr = -90; 
} else if(($z == 0) && ($x < 0)) { 
$yr = 90; 
} else if($z > 0) { 
$yr = 180 - atan2($x,$y); 
} else if($z < 0) { 
$yr = atan2($x,$y); 
} 
// X- ROTATION 
if (($y == 0) && ($z >= 0)) { 
$xr = -90; 
} else if(($y == 0) && ($z < 0)) { 
$xr = 90; 
} else if($y > 0) { 
$xr = 180 - atan2($z,$y); 
} else if($y < 0) { 
$xr = atan2($z,$y); 
} 
// Z- ROTATION 
if (($y == 0) && ($x >= 0)) { 
$zr = -90; 
} else if(($y == 0) && ($x < 0)) { 
$zr = 90; 
} else if($y > 0) { 
$zr = 180 - atan2($x,$y) - 180; 
} else if($y < 0) { 
$zr = atan2($x,$y) ; 
} 
PHP-Code:
	
	
function get_quaternionByEulerRotation($xr,$yr,$zr){ 
$q1 = cos($xr/2) * cos($yr/2) * cos($zr/2) + sin($xr/2) * sin($yr/2) * sin($zr/2); 
$q2 = sin($xr/2) * cos($yr/2) * cos($zr/2) - cos($xr/2) * sin($yr/2) * sin($zr/2); 
$q3 = cos($xr/2) * sin($yr/2) * cos($zr/2) + sin($xr/2) * cos($yr/2) * sin($zr/2); 
$q4 = cos($xr/2) * cos($yr/2) * sin($zr/2) - sin($xr/2) * sin($yr/2) * cos($zr/2); 
return array($q2,$q3,$q4,$q1); 
} 
Hab ich einen Denkfehler???
bin mal gespannt ob mir da jemand helfen kann...
Stefan
 
          
 Moderator
 Moderator 
 
							
						 
							
						
Kommentar