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

1. ## 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. 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. 3. I can confirm that works. Thanks! I don't know how I missed the simple subtraction idea... Popular pages Recent additions 