x


how do I compare Quaternions?

I'm trying to compare two rotations. I'm checking to see if they are equal like this

 if(rot==prevrot){
 dosomething;
 }
 else{
 dosomethingelse
 }


Here's an example of the Debug.Log of two that were not equal according to the if statement. But look at the output...

 prevrot=(0.0, 0.0, 0.0, 1.0) rot=(0.0, 0.0, 0.0, 1.0)

Why doesn't the Debug.Log output match the if statement?

more ▼

asked Jul 22, 2012 at 04:17 AM

dansav gravatar image

dansav
522 465 372 416

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

internally quaternion stored as 4 floats, so two quaternions can be different but both logs as (0,0,0,1) due to precision of float.

http://docs.unity3d.com/Documentation/ScriptReference/Quaternion.Angle.html

use this to compare two rotations by angle between them - for example if angle is lower then some threshold then these quaternions are same

more ▼

answered Jul 22, 2012 at 06:32 AM

ScroodgeM gravatar image

ScroodgeM
8.4k 1 5 14

Thanks for the clear explanation and solutions.

Jul 22, 2012 at 07:22 AM dansav
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x784
x85
x58

asked: Jul 22, 2012 at 04:17 AM

Seen: 4515 times

Last Updated: Jul 22, 2012 at 07:22 AM