Artwork > Finished Works and Works in Progress

Paddle Steamer engine

<< < (7/9) > >>

Raxx:
ENSONIQ5, I know your pain. In case you may have missed it, there's a RPYtoQuaternion function in ASL that'll handle that all that nasty conversion and convert your roll/pitch/yaw for you.


--- Code: ---point4 RPYtoQuaternion(float roll, float pitch, float yaw)
      // Compute the primary unit quaternion defined by
      // applying a roll , then a pitch, and finally a yaw
      // specified in degrees.

--- End code ---

ENSONIQ5:
Yeah, I know about that one, however the QuaterniontoRPY function is conspicuous by its absence.  Since I'm deriving motion from a rotating object (ie. getting the orientation value), I need to convert to RPY to run oscillations, either rotational (like a pendulum) or linear (like a sliding piston).  I'm planning to jump out to a simple project and analyse a few RPYtoQuaternion operations to see if I can work out what's actually going on before working out the reverse process, I'd love to get a handle on this since it is often used in 3D geometry to avoid 'gimbal lock' issues and I kinda feel like it's something I should know about.  One Wiki article I started to read on the subject of quaternions started to get into 'unreal numbers' (those impossibilities that equal a negative number when squared, ie x^2=-1) and I recall that it was these little $#@&s that back in high school marked the limit of my mathematical ability and interest and helped me to cross 'mathematician' off my careers options list!

Raxx:
Ugh, sorry about the obvious reference. I've been staring at ASL for the last 12 hours ;)

I've made my fair share of attempts to convert from Quaternions to Vectors/YPRs and back again. Only once did I get really close. It's unfortunate but it seems that for the most part it's impossible to get a 100% conversion. Or at least, that's how it's been for me.

For example, I did a quick run with this (it's a mess, sorry), and it doesn't work:

--- Code: ---/*
From: http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/
http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/index.htm

*/

#command("object");

file $output;
float $test, $roll, $pitch, $yaw;
quaternion $q, $qC;

$output.open("$console", "w");

/* Our beginning Roll, Pitch, and Yaw */
$yaw = 20;
$pitch = 45;
$roll = 50;

$output.print("\nStarting RPY: %.3f, %.3f, %.3f \n", $yaw, $pitch, $roll);

/* Now convert it to a quaternion using Anim8or's built-in function */
$q = RPYtoQuaternion($roll, $pitch, $yaw);
$output.print("RPYtoQuaternion: %.3f, %.3f, %.3f, %.3f \n", $q);

/* Now convert it to quaternion the hard way */
$q.w = sqrt(1.0 + cos($yaw/2)*cos($pitch/2) + cos($yaw/2)*cos($roll/2) - sin($yaw/2)*sin($pitch/2)*sin($roll/2) + cos($pitch/2)*cos($roll/2))/2;
$q.x = (cos($pitch/2)*sin($roll/2) + cos($yaw/2)*sin($roll/2) + sin($yaw/2)*sin($pitch/2)*cos($roll/2))/(4.0*$q.w);
$q.y = (sin($yaw/2)*cos($pitch/2) + sin($yaw/2)*cos($roll/2) + cos($yaw/2)*sin($pitch/2)*sin($roll/2))/(4.0*$q.w);
$q.z = (-sin($yaw/2)*sin($roll/2) + cos($yaw/2)*sin($pitch/2)*cos($roll/2) + sin($pitch/2))/(4.0*$q.w);

$output.print("Manual Quaternion: %.3f, %.3f, %.3f, %.3f \n", $q);

/* Now let's try and convert it back...*/
$test = $q.x*$q.y + $q.z*$q.w;

if ($test > 0.499) {
$yaw = 2 * atan2($q.x,$q.w);
$pitch = PI/2;
$roll = 0;
}
if ($test < -0.499) {
$yaw = -2 * atan2($q.x,$q.w);
$pitch = -PI/2;
$roll = 0;
}

$qC.x = $q.x*$q.x;
$qC.y = $q.y*$q.y;
$qC.z = $q.z*$q.z;

$yaw = atan2(2*$q.y*$q.w-2*$q.x*$q.z , 1 - 2*$qC.y - 2*$qC.z);
$pitch = asin(2*$test);
$roll = atan2(2*$q.x*$q.w-2*$q.y*$q.z , 1 - 2*$qC.x - 2*$qC.z);

$output.print("Converted RPY: %.3f, %.3f, %.3f \n\n", $roll*(180/PI), $pitch*(180/PI), $yaw*(180/PI));

/*
$RPYConverted.x = atan2(1 - 2*pow($q.y, 2) - 2*pow($q.z, 2), 2*$q.y*$q.w - 2*$q.x*$q.z);
$RPYConverted.y = asin(2*$q.x*$q.y + 2*$q.z*$q.w);
$RPYConverted.z = atan2(2*$q.x*$q.w - 2*$q.y*$q.z, 1 - 2*pow($q.x, 2) - 2*pow($q.z, 2));

$output.print("Converted RPY: %.3f, %.3f, %.3f \n\n", $RPYConverted.x*(180/PI), $RPYConverted.y*(180/PI), $RPYConverted.z*(180/PI));
*/

$output.close();

--- End code ---

ENSONIQ5:
Hmmm, thanks for that Raxx, gives me a good starting point for picking this thing apart.  Much appreciated.

Blick Fang:
You guys blow my mind.    8)  Your knowledge gives me the confidence I need, to push ahead with Anim8or.  But I am stuck on what to do next.  I need to make a mobile figure.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version