Ok I'm making a 3d game and my problem is that I wanted to get what will be the new x,y,z coordinate depending on the rotation of the parent bone...see the image below for better understanding... see in fig a the parent bone(B) and child bone(A) both share the same x and y, and rotated at 0...Now in figure b,see the parent bone rotates 45 degree in let say y coordinate,now I found out how to get the new x based on the given side and angle with this formula: newx = tan(yrot)xlength of the parent bone...But suddenly I realized that not only rotation in y affects the x coordinate BUT also if you rotate it on z axis...Now I'm confused what to do to relate that z rotation on my formula...I hope you understand what the problem is...And if someone can help me...These are the given so far:location of parent bone(B)let's say 0,0,30 and location of the child bone 0,0,15 and the angle that was formed 45 degree and lastly we know what is the length of the bones 10x2...PLEASE HELP!!!

**0**

# Help with getting the change in x,y,z coordinate in 3d space!

###
#2
Moderators - Reputation: **7868**

Posted 18 February 2013 - 10:53 AM

You should get familiar with linear algebra. This becomes a fairly trivial with vectors and matrices.

Each bone can simply be defined as having location in the coordinate frame of its parent bone and a transformation that this bone applies. That will uniquely define the entire bone structure. In addition to that, you can add any information you want to the bones, of course.

Your choice of bone names is a little bit off for the sake of explaining the situation and to extend the explanation to more bones, so let's say instead that bone A is the first bone, bone B is attached to bone A, and bone C is attached to bone B, and so on. Each bone has a position **p** (a vector) and an orientation **R** (a rotation matrix). Let's say that each bone also has a translation matrix **T** that simply corresponds to a translation matrix by its position **p**. For example, A.**R** is the rotation matrix of bone A, and B.**T** is the translation matrix for bone B, and so on.

At this point, finding the orientation and location of any bone in an arbitrary chain of bones becomes fairly trivial. To determine a bone's parent transformations, you simply multiply all its parent transformations.

- The bone A is the parent bone and is thus not subject to any prior transformations. Its location is A.
**p**and its orientation is A.**R**, so you can use these matrices to draw the bone itself. - The bone B has the bone A as its parent. Its location is B.
**p**in A's coordinate frame, and so its location becomes (A.**T*** A.**R**) * B.**p**. - The bone C has the bone B as its parent. Its location is C.
**p**in B's coordinate frame, and so its location becomes ((A.**T*** A.**R**) * B.**T*** B.**R**) * C.**p**. - The bone D has the bone C as its parent. Its location is D.
**p**in C's coordinate frame, and so its location becomes (((A.**T*** A.**R**) * B.**T*** B.**R**) * C.**T*** C.**R**) * D.**p**. - And so on...

In your case, you would have defined the bones as follows:

- A.
**p**= (0,0,30) - A.
**R**= rotation matrix of 45 degrees - B.
**p**= (0,0,15) - B.
**R**= rotation matrix of 0 degrees

Note that bone B (which is bone A in your picture) does not have any rotation on its own; its rotation comes from its parent bone A (bone B in your picture).

Note that, depending on which conventions you choose for your linear algebra, you may have to change the order of the translation and the rotation matrices, multiply child bones on the left side, and/or multiply the position vector on the left side instead.

###
#3
Members - Reputation: **103**

Posted 18 February 2013 - 05:37 PM

You should get familiar with linear algebra. This becomes a fairly trivial with vectors and matrices.

Each bone can simply be defined as having location in the coordinate frame of its parent bone and a transformation that this bone applies. That will uniquely define the entire bone structure. In addition to that, you can add any information you want to the bones, of course.

Your choice of bone names is a little bit off for the sake of explaining the situation and to extend the explanation to more bones, so let's say instead that bone A is the first bone, bone B is attached to bone A, and bone C is attached to bone B, and so on. Each bone has a positionp(a vector) and an orientationR(a rotation matrix). Let's say that each bone also has a translation matrixTthat simply corresponds to a translation matrix by its positionp. For example, A.Ris the rotation matrix of bone A, and B.Tis the translation matrix for bone B, and so on.

At this point, finding the orientation and location of any bone in an arbitrary chain of bones becomes fairly trivial. To determine a bone's parent transformations, you simply multiply all its parent transformations.

- The bone A is the parent bone and is thus not subject to any prior transformations. Its location is A.
pand its orientation is A.R, so you can use these matrices to draw the bone itself.- The bone B has the bone A as its parent. Its location is B.
pin A's coordinate frame, and so its location becomes (A.T* A.R) * B.p.- The bone C has the bone B as its parent. Its location is C.
pin B's coordinate frame, and so its location becomes ((A.T* A.R) * B.T* B.R) * C.p.- The bone D has the bone C as its parent. Its location is D.
pin C's coordinate frame, and so its location becomes (((A.T* A.R) * B.T* B.R) * C.T* C.R) * D.p.- And so on...
In your case, you would have defined the bones as follows:

- A.
p= (0,0,30)- A.
R= rotation matrix of 45 degrees- B.
p= (0,0,15)- B.
R= rotation matrix of 0 degreesNote that bone B (which is bone A in your picture) does not have any rotation on its own; its rotation comes from its parent bone A (bone B in your picture).

Note that, depending on which conventions you choose for your linear algebra, you may have to change the order of the translation and the rotation matrices, multiply child bones on the left side, and/or multiply the position vector on the left side instead.

Ok thanks for the info,Trying Linear Algebra now thanks.

EDIT:it's now make sense,I'm learning from it thanks....

this is my signature