# calculate difference of euler angles between two dynamic moving objects

46 views (last 30 days)
Florian Mayerle on 12 Aug 2019
Commented: Florian Mayerle on 12 Aug 2019
Hi,
I have two Objekts in same coordinate System. I want to calculate the difference between object1 and object2 in yaw, pitch and roll by comparing the rotation matrix .
If the objects dont move and if it has almoast the same orientation I can calculate each position relative to the origin and compare the angles, this already works verry good.
But if the objcts move and the orientation differs a lot I get allways a wrong angle differnce on one of the axises.
I dont know hot two fix this Problem.
Is there any sollution to calculate the difference between Rotation Matrixes/Quaterions/Axis and Angle and get solid results without singularitys?
Greetings
Florian

Jim Riggs on 12 Aug 2019
Edited: Jim Riggs on 12 Aug 2019
You have two objects described in a common reference frame. Lets call the objects A and B, and the frame is the I frame. So if Direction cosine matrix [I -> A] represents the transformation from the I frame to body A frame, and [I -> B] is the DCM which transforms coordinates from I to body B, then the transformation from A to B is:
[A -> B] = [I -> B] [I -> A]^T (where [I -> A]^T is the transpose of [I -> A]
This is the same as [A -> B] = [I -> B] [A -> I].
Now you can extract the Euler angles from [A -> B] which represent the rotation to get from A to B.
Florian Mayerle on 12 Aug 2019
B*transpose(A) seems to give me the right output, I have to do some validatioin first to be sure.
But anyway it looks way better than before now.
Jim Riggs, thanks a lot for your time and effort.

### More Answers (1)

Chris on 12 Aug 2019
Are you trying to compare the rotation matries directly or are you compairing the euler angles? I am not sure you can use the matricies directly but looking at the euler angles is a needed first step to debug your code before doing anything more complicated. Also remember to account for heading wrap around at north.
##### 1 CommentShow NoneHide None
Florian Mayerle on 12 Aug 2019
I try to smehow compare the positon between the two objekts.
I have a rotation vector (rodrigues) as input and convert it to rotation matrix with:
rotationVectorToMatrix
Then i calculated euler angles relative to the Origin between each object and compare the output but sometimes I get values whitch seems to be wrong and I cant find the error.