# Quaternion representing rotation from shoulder to hand

I am provided with 3 quaternions. One for the shoulder, one for the elbow, and one for the hand. What I want is to obtain a single quaternion representing the rotation from the shoulder to the hand, essentially removing the elbow in the process. I have a diagram below to better illustrate this.

Assuming that both of the above sections (forearm and upper arm) are of the same length, how could this be calculated?

• Do you have bone lengths as well, or you need just an orientation? Commented Nov 7, 2018 at 5:41
• @Kromster I really just need an orientation, I can assume the lengths to be arbitrary for my use case Commented Nov 7, 2018 at 12:36
• By arbitrary lengths you mean exactly what? Take a piece of paper and try to see how lengths drastically affect the result in 2D. Commented Nov 7, 2018 at 12:42
• @Kromster I meant that the lengths are the same and do not really matter, they could just be 1 unit in some unit. Not really looking for anything too exact. Commented Nov 7, 2018 at 16:00

Assuming that both of the above sections (forearm and upper arm) are of the same length

Then let 1 unit of our coordinate system be the length of one arm segment. Let's also assume the joint quaternions we have are arranged so they point a unit "forward" vector along the length of the bone.

elbowOffsetFromShoulder = shoulderRotation * forward;

handOffsetFromShoulder = elbowOffsetFromShoulder + shoulderRotation * elbowRotation * forward;


Now we can form a quaternion that orients the forward vector to point from the shoulder to the hand with a LookRotation convenience method. This still leaves us with one degree of freedom: the twist of the rotation about the shoulder-hand line. We can arbitrarily choose to try to align the up vector of our resulting rotation as close as possible with the shoulder's local up.

shoulderToHandRotation = Quaternion.LookRotation(handOffsetFromShoulder, up);


If you're in an engine like Unity you'll have a convenience method like this already. If not, you can implement your own version, or construct a matrix with the desired orientation (eg. column 3 = normalize(handOffsetFromShoulder), column 2 = normalize(up - dot(up, column 3) * column 3, column 1 = cross(column 2, column3)) and convert the matrix to a quaternion.

Note that this quaternion generally points in a different direction than the forearm's orientation, so if you then stack a hand or pointer with a particular orientation on the end, it will need adjustment to stay aligned with its new parent, ie.

newHandRotation = Inverse(shoulderToHandRotation) * shoulderRotation * elbowRotation * handRotation;

• This seems to be what I am looking for! Just to clarify however, would the forward vector be in relation from the torso toward the direction that the arm is in, or would it be the direction that the model is facing? Also, I am using Python/Blender’s mathutils to do this, would you happen to know of any premade implementations of LookRotation? Commented Nov 7, 2018 at 16:12
• The forward direction isn't in relation to any object, it's the abstract choice of which axis you've chosen to "mean" forward. Unity, for instance, adopts the convention that z+ is "forward" and y+ is "up". If for example in the upper arm's local coordinate space, the shoulder is at (0, 0, 0) and the elbow is at (0, 0, 6.3), then the "forward" direction is the z+ axis, and a unit vector in that direction is (0, 0, 1). As for doing this in Blender, the vector.toTrackQuat method looks promising, or you can construct a matrix as described above and use matrix.toQuat Commented Nov 7, 2018 at 16:27
• Thanks! Final question, where exactly did you get that matrix from? Commented Nov 7, 2018 at 17:18
• I just built it following the rule that if you're transforming a vector like matrix * vector, then you can build the matrix out of columns corresponding to where you want the (1,0,0) (0,10) (0,0,1) basis vectors to end up after the transformation. I used Unity conventions to map the forward direction to the z axis (3rd column), up to y (2nd), right to x (1st). I subtracted a projection to ensure our up vector is perpendicular to z, and used the left-hand rule to construct a mutually-perpendicular right vector using a cross product. Commented Nov 7, 2018 at 17:30
{"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "url": "https://gamedev.stackexchange.com/questions/165143/quaternion-representing-rotation-from-shoulder-to-hand/165151#165151", "fetch_time": 1718403292000000000, "content_mime_type": "text/html", "warc_filename": "crawl-data/CC-MAIN-2024-26/segments/1718198861575.66/warc/CC-MAIN-20240614204739-20240614234739-00713.warc.gz", "warc_record_offset": 237827035, "warc_record_length": 38537, "token_count": 1049, "char_count": 4335, "score": 3.546875, "int_score": 4, "crawl": "CC-MAIN-2024-26", "snapshot_type": "latest", "language": "en", "language_score": 0.9258666634559631, "file_path": "/sailhome/yjruan/project/latent-lm/data/processed/finemath-4plus/finemath-4plus/train-00022-of-00064.parquet"}