Thread: Quaternion fun... Is there a more efficient way to do this?

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    2

    Quaternion fun... Is there a more efficient way to do this?

    Hi all,

    I'm modeling an object's rotation using a quaternion (A). Occasionally, I would like to re-orient the object with a new yaw, but keep the object's current pitch and roll.

    Right now I accomplish this as follows:
    -calculate the yaw of the object's quaternion (A) (euler yaw value)
    -create a new quaternion (B) with the inverse of the yaw value
    -multiply the object's quaternion (A) by this new quaternion (B) so the yaw of the resulting quaternion (C) is now 0, but the yaw and pitch are the same as the object's quaternion (A)
    -create a quaternion (D) using the NEW yaw value
    -multiply the 0 degree yaw quaternion (C) by the NEW quaternion (D)


    That seems incredibly inefficient to me and I'm sure there is a better way.... but I am rather new to quaternions. I would appreciate any advice!

    I feel like there should be some way for me to create a quaternion with the NEW yaw value, then use it to directly replace the object's quaternion z, and adjust the w value?

  2. #2
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    Code:
    -Calculate current yaw
    -Create a quaternion that represents the difference in angles (eg, yaw = (new yaw) - (current yaw))
    -Multiply
    I do believe that will work. It takes a few steps out of your process, at any rate.
    But I can't think of a way that doesn't involve converting to/from euler angles.
    Consider this post signed

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    2
    I can confirm that works. Thanks! I don't know how I missed the simple subtraction idea...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Expressing a quaternion with zero rotation
    By shrink_tubing in forum C++ Programming
    Replies: 12
    Last Post: 08-18-2010, 03:44 AM
  2. Quaternion Rotation
    By psychopath in forum Game Programming
    Replies: 16
    Last Post: 07-23-2006, 03:28 PM
  3. Quaternion question
    By Mr Q in forum Game Programming
    Replies: 15
    Last Post: 04-21-2004, 09:34 AM
  4. Quaternion class problem
    By Lurker in forum C++ Programming
    Replies: 14
    Last Post: 11-18-2003, 06:01 PM
  5. optimizing my quaternion code
    By confuted in forum Game Programming
    Replies: 9
    Last Post: 08-16-2003, 08:50 PM