Skip to main content
GameDev.net gamedev.net
🔒 Locked

Angles between two vectors in 3D space

Started by prolog Apr 12, 2010 at 8:00 AM 14 replies 3.1k views
Original Post
prolog
prolog
Please take a look at this picture I have two parts connected by a 'joint' in 3D space. Imagine part 1 is your right hand, part 2 is your right shoulder bone and the joint is your right shoulder socket. You can rotate your right hand freely in 3D space. I believe the two lines are related by two angles. What's the best and the fastest way to measure those two angles? If line 1 is moved to a new position in space, line 2 should also be moved accordingly, keeping those angles constant. How do I go about that?
Mussi
Mussi
What does this:
Quote:
I have two parts connected by a 'joint' in 3D space. Imagine part 1 is your right hand, part 2 is your right shoulder bone and the joint is your right shoulder socket. You can rotate your right hand freely in 3D space.

have to do with this:
Quote:
believe the two lines are related by two angles.

And what two angles are you talking about?

Quote:
If line 1 is moved to a new position in space, line 2 should also be moved accordingly, keeping those angles constant.


How do I go about that?


Move line 2 with the same amount. But I'm quite sure that's not what you mean, are you trying to get line 2 out of line 1 with just an angle value?
prolog
prolog
Stick figure of a person standing


This picture might make you understand better.

Initially, body part 1-4 is orthogonal to 1-2. If I change it to 180 degrees (raising your hand), the locations of 4-6 and 6-8 should also change, while preserving their current angles.



In a nutshell, if I move 1-4 to any position, the rest of the hand should follow accordingly

The same goes for the legs. If I raise the legs, the feet should follow suit.
Mussi
Mussi
In order to achieve that you need a tree of transformations. What you'd get is something like this:

Shoulder     |Upper arm     |Lower arm     |    Hand    /  |Thumb  Index finger


First you transform the shoulder, then you multiply that transformation with the upper arm transformation, which should be relative to the shoulder, and then you take that transformation and multiply that with the lower arm transformation and this goes on till you reach the fingers. By rotating the shoulder now(or any other limb), all the other limbs that 'follow' will rotate as well and keep their position relative to the rotated limb.
prolog
prolog
Thanks.
I have no problem with body part tree.

I'm just stuck in the transformation part. I have no clue how to measure the relative angle(s) between two body parts and how to transform the body parts to new locations while preserving their relative angle(s)
Mussi
Mussi
Why would you want to measure the angle? Lets say you start out with a stretched out arm, every angle relative to their parent limb is 0 degrees(or 180 degrees, depends on how you look at it). If you rotate the the parent limb, all child limbs will still have an angle of 0 degrees relative to that parent. If you transform the way I described in my previous post that is.
prolog
prolog
Well the pose in the picture is just an example. Actually the posture is arbitrary (sitting, standing, running.. etc). So you have to know the angles.

The hands may not necessarily be all stretched out 180'
Mussi
Mussi
So what is it that you are trying to do? Are you trying to animate the body?
prolog
prolog
Yes
Mussi
Mussi
Well you start out with an initial pose, all transformations being applied happen from this pose. Normally you would read the transformations from a file and what happens when you play a biceps curl animation is this(assuming initial pose shown on the left in your stick figure picture): the shoulder gets rotated over time by 90 degrees about the z- and x-axis(assuming the character faces in the z direction) and translated to the correct position. The transformation matrix used for the shoulder now gets multiplied by the transformation matrix of the upper arm which only consists of the initial translation matrix it had. The resulting matrix now gets used for the lower arm. First the lower arm gets rotated by 90 degrees about the x-axis and translated by the initial translation, this gives the transformation matrix for the lower arm relative to the upper arm. Multiplying the two matrices gives the transformation matrix that results in the lower arm getting up to the correct position with the right orientation.

So the relative angles between the limbs is always known, because you set them.
Zakwayda
Zakwayda
Quote:
Original post by prolog
So you have to know the angles.
Why? It sounds to me like you just need a transform hierarchy, just as Mussi said.

I think your idea that 'the angles' have some special significance is somewhat misguided; a child's transform relative to its parent should give you all the information you need to determine its position and orientation in world space.
prolog
prolog
Quote:
Original post by Mussi
The transformation matrix used for the shoulder now gets multiplied by the transformation matrix of the upper arm which only consists of the initial translation matrix it had.


Sorry I still don't understand. What's the transformation matrix of the upper arm?
All I have initially is a list of Cartesian coordinates of the body points.





I'm kinda new to this thing. What would be the best way to represent a 3D human model? I'm currently using only Cartesian coordinates. Do I also need to store transformation matrix for each joint?

My goal is to reconstruct a 3D human model from a given image of a person.
Mussi
Mussi
Quote:
Original post by prolog
Sorry I still don't understand. What's the transformation matrix of the upper arm?
All I have initially is a list of Cartesian coordinates of the body points.

the transformation matrix of the upper arm is the transformation matrix of the shoulder multiplied by the translation matrix of the upper arm. If for example the centre of the upper arm mesh is in the middle of the arm, and the arm is of length 30cm, the translation matrix of the upper arm should translate it 15cm down.

Quote:
Original post by prologDo I also need to store transformation matrix for each joint?


Yes, you only need to store the transformations of the initial pose.
ninmonkeys
ninmonkeys
Is this a good example to se Quaternions?

Here's example psuedo code on the tree. Assuming human Local coords is relative torso.

# matrix coords already translated to humans location.DrawTorso()MatrixPush() # save translate world to local coords# translate = local + armRTranslate(armR)DrawArm()MatrixPush()  # translate = armR + wrist      Translate(wrist)  DrawWrist()  MatrixPush()    #Do fingers for loop  For i in xrange(1,5):    MatrixPush()    Translate(finger i)    DrawFinger()    MatrixPop()    MatrixPop() #wristMatrixPop() # armMatrixPop() #torso /. Local coords

Typing on iPod, so excuse typo or indentation. To give you a quick example.

If you were thinking of defining the arm up, down, and rwrist by relave angles, I think Quaternions help. That they can multiply two angles?
Ariste
Ariste
Quote:
Original post by prolog
I'm kinda new to this thing. What would be the best way to represent a 3D human model? I'm currently using only Cartesian coordinates. Do I also need to store transformation matrix for each joint?


Yes, each joint needs its own transform relative to its parent. Instead of storing the Cartesian coordinates of each joint, store a matrix (or whatever method of storing transformations you like) that describes the joint's position and orientation relative to its parent. The entire body is then represented as a series of transforms relative to some arbitrary root node.

To get the position/orientation of a joint, simply traverse the body from the root to the desired joint, concatenating transforms as you go. This system is great, because if you want to, say, raise the left arm, you need only concatenate a rotation matrix (or quaternion) with the current transform of the left shoulder. This will rotate the shoulder joint, and since every subsequent transform is expressed relative to its parent, it will effectively raise the entire left arm as desired.

Quote:
Original post by ninmonkeys
Typing on iPod...


Ouch.
Sneftel
Sneftel
Quote:
Original post by ninmonkeys
If you were thinking of defining the arm up, down, and rwrist by relave angles, I think Quaternions help. That they can multiply two angles?

The use of quaternions versus rotation matrices here makes no difference to the issues at hand. They're just different representations of rotation in 3-space.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.