Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 9 of 9

Thread: 3D rotation mismatch calculation

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2011
    Posts
    9

    Lightbulb 3D rotation mismatch calculation

    I am trying to figure out a way to compare the 3D rotation of two objects and find a measure of HOW MUCH they are mismatched. The only thing I have is I have the two objects' matrices or quaternions. Is there some way to say how much their rotations differ?

    The reason I need it is because I'm comparing two methods to rotate 3D objects and experiment participants have to rotate an object to match a target. i.e. I need a way to quantify the mismatch.

    Any advice would be appreciated.

    Jubei

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,125
    I may be missing something, but think about it this way:

    1) You have a rotation R1 from a base orientation O to rotated orientation A (gold standard)
    2) You also have a rotation R2 from the base orientation O to a rotated orientation B

    You want to find out what the rotation is from A to B. In other words:

    A-to-B
    = A-to-O * O-to-B
    = R1^-1 * R2

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2011
    Posts
    9
    Quote Originally Posted by Dark Photon View Post
    I may be missing something, but think about it this way:

    1) You have a rotation R1 from a base orientation O to rotated orientation A (gold standard)
    2) You also have a rotation R2 from the base orientation O to a rotated orientation B

    You want to find out what the rotation is from A to B. In other words:

    A-to-B
    = A-to-O * O-to-B
    = R1^-1 * R2
    I'm not sure I understand your response. R1 is a matrix? Because my rotation in 3D is either described by a quaternion or by a 3x3 matrix. I can't quite see how your calculation will give me a measure (ideally a scalar) that indicates the amount of "mismatch".

  4. #4
    Junior Member Regular Contributor
    Join Date
    Apr 2012
    Posts
    164
    Quote Originally Posted by Jubei View Post
    .... find a measure of HOW MUCH they are mismatched..
    How about computing the angle between x and x', y and y', and z and z', where x, y, and z are the rows of the target matrix, and x', y', z' are the rows of the rotation matrix attempting to match the target matrix?

  5. #5
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,125
    Quote Originally Posted by Jubei View Post
    I'm not sure I understand your response. R1 is a matrix? Because my rotation in 3D is either described by a quaternion or by a 3x3 matrix. I can't quite see how your calculation will give me a measure (ideally a scalar) that indicates the amount of "mismatch".
    Well, I'm not sure exactly what you want to measure. If you compute the A-to-B transform as a matrix and run it through your favorite rot-matrix-to-unit-quaternion function, then you'll have a quat that tells you by what angle they differ, and even about what axis to rotate to get it. (You could prob even do this with pure quats and it'd likely be cheaper).

    Another option: take unit vectors A and B, and use the dot product to compute the angle. Cross to get the axis.

    Since you just said rotation difference, I'm assuming there is no translation difference, or you don't care about that.

  6. #6
    Junior Member Newbie
    Join Date
    Aug 2011
    Posts
    9
    Quote Originally Posted by Carmine View Post
    How about computing the angle between x and x', y and y', and z and z', where x, y, and z are the rows of the target matrix, and x', y', z' are the rows of the rotation matrix attempting to match the target matrix?
    The problem with that is that if I take the absolute value of sin(theta) or cosine(theta) on each individual axis, the sin(theta) for example might be very close even though the object is facing almost 2*pi degrees to the opposite direction. Then if I use degrees as a comparison I might get 180 degree difference on some axis even though the objects are almost matched (just because it has rotated around almost full circle).

    So I don't think comparing each individual axis works. At the end of the day I want to say "that user matched the rotation of the cursor to the target 90% or... 10% " depending on how close they matched it.

  7. #7
    Junior Member Newbie
    Join Date
    Aug 2011
    Posts
    9
    First of all let me say that I really appreciate the efforts to help.

    Quote Originally Posted by Dark Photon View Post
    Well, I'm not sure exactly what you want to measure. If you compute the A-to-B transform as a matrix and run it through your favorite rot-matrix-to-unit-quaternion function, then you'll have a quat that tells you by what angle they differ, and even about what axis to rotate to get it. (You could prob even do this with pure quats and it'd likely be cheaper).
    Hmm... aren't there many different combinations of axis angle to get to achieve a certain rotation? So if I get two quaternions for the two orientations I want to compare couldn't it be that the angle magnitude is bigger but the unit axis a totally different one, as such the comparison would be meaningless? I might be missing something, please correct me if I'm wrong.

    Quote Originally Posted by Dark Photon View Post
    Another option: take unit vectors A and B, and use the dot product to compute the angle. Cross to get the axis.
    Which unit vectors would those be? Apologies in advance but I don't understand.

    Quote Originally Posted by Dark Photon View Post
    Since you just said rotation difference, I'm assuming there is no translation difference, or you don't care about that.
    Yes it's unimportant, I'm already measuring this as the distance between the center of the objects' bounding boxes.
    Last edited by Jubei; 01-20-2013 at 07:57 PM.

  8. #8
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,125
    Quote Originally Posted by Jubei View Post
    Hmm... aren't there many different combinations of axis angle to get to achieve a certain rotation? So if I get two quaternions for the two orientations I want to compare couldn't it be that the angle magnitude is bigger but the unit axis a totally different one, as such the comparison would be meaningless?
    No you don't compare them directly. From them you'd composite them to compute a single transform which rotates from A to B (via matrices or directly). But seems simpler just to use the vector dot/cross I described next.

    Related link:
    * http://www.gamedev.net/topic/423462-...o-quaternions/

    Websearch "angle between two quaternions" for more.

    Which unit vectors would those be? Apologies in advance but I don't understand.
    Envision a unit sphere. The center is your rotation origin (call it X). You have two rotation orientations, which correspond to 2 points on the sphere (unit vectors from the center -- call them A and B). Sounds like you just want to know what the angle difference is between vectors XA and XB. No?
    dot product, inverse cosine, and you've got the angle.
    Last edited by Dark Photon; 01-21-2013 at 06:02 AM.

  9. #9
    Junior Member Newbie
    Join Date
    Aug 2011
    Posts
    9
    Thanks for the responses I will investigate further!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •