Using quaternions or rotating around 3 axes with euler rotations

Hey Math Gurus,

I’m having a problem that is just beyond me. I’m redoing the joints array for my character object. Right now it’s an array of points in 3d space. Whenever I move between states ( say standing and sitting ) I have two arrays of the positions for each state and I just find the difference between the start state and end state over the amount of time it takes to move from one to the other and put those values in my drawArray. This has lead to some pretty strange behavior. Let’s say my arm is hanging downward and I’m moving to a state where the arm is reaching up. As the arm moves upward, it doesn’t move outward. It just shrinks into itself until the shoulder, elbow, wrist, and hand are all the same nub, then it grows up. I could make an outward state and then move into the intermediate state between the two, but the shrinking issue would still be occuring, just less noticeable.

What I’m trying to do is move away from arrays of vertices to an array of rotations and fixed distances between joints. So instead of the point in 3d space where the elbow is stored, I’d store the rotations from shoulder-to-elbow then draw the elbow at sholderToElbowDistance out from shoulder location. If I’m rotating along one axis, then this works and all is well in my little world. When I try to rotate along two or more axes ( <-- did y’all know that’s the plural form of axis? ) some funky junk starts happening.

According to the Internet, the answer is quaternions. The problem is, I’m stupid. I can’t figure these things out. I’ve seen some awesome examples of how to rotate a camera with these things, but I can’t take that and apply it to what I’m trying to do. Could someone give me the dumbed down example I’m looking for?

If you can take what I’m about to write and ‘fix’ it, that should be enough to get me rolling. I’m just one of those people who need an example before the concept can develop.

// Pretend my character is sticking their arm at a diagonal direction to the side in such a way that there’s a difference along each axis.

// this picture should give you the idea

// the shoulder can be at the origin and adjusted later, I’ve had a lot of luck adjusting things correctly, it’s just the rotations that are getting me
// positive x if forward
// positive y is left
// positive z is up … yes I know y is usually up but remember, I’m stupid
float xShoulderToElbowDegree = 45f;
float yShoulderToElbowDegree = 45f;
float zShoulderToElbowDegree = 45f;
float shoulderToElbowDist = 1.14f;

float elbowX,elbowY,elbowZ=magic();
// use x,y,z ( 0,0,0) coordinates of shoulder to get x,y,z vertex for elbow

float xElbowToWristDegree = 20f;
float yElbowToWristDegree = 45f;
float zElbowToWristDegree = 65f;
float elbowToWristDist = .93f;

float wristX,wristY,wristZ=magic();

// same deal, now that I have x,y,z vertex of elbow how to use the above to get x,y,z vertex of wrist?
// or, we could draw the elbow-to-wrist at the origin too and then I can move it around… I just don’t understand how to get that 3d spot for the wrist given three axes to rotate around