Quaternion precision problem?

   1738   4   1
User Avatar
Member
337 posts
Joined: June 2013
Offline
How can I rotate a {1,0,0}vector by 180 degs on Z axis with quaternions so the result is {-1,0,0}, or if I rotate by 90 degs the result is {0,1,0}. Quaternion rotation always introduces some infinitesimal garbage, while in contrast, for example, maketransform()performs the proper result. Is the problem the angle conversion? Because radians(180) == PIoutputs 0.



vector v = {1,0,0} ;

v@quata0 = qrotate(quaternion(PI, {0,0,1}), v) ;
v@quatb0 = qrotate(quaternion(radians(180), {0,0,1}), v) ;

v@quata1 = qrotate(quaternion(PI/2, {0,0,1}), v) ;
v@quatb1 = qrotate(quaternion(radians(90), {0,0,1}), v) ;

s@n_spacer = "" ;

v@mat0 = v * maketransform(0, 0, 0, set(0,0,180), 1) ;
v@mat1 = v * maketransform(0, 0, 0, set(0,0,90), 1) ;
Edited by probiner - July 31, 2022 09:25:52
User Avatar
Member
7741 posts
Joined: Sept. 2011
Offline
Well, it's using float math, what do you expect? You would need infinite precision to get exactly 0. Make transform gets around this by special casing since it takes degrees as input.
User Avatar
Member
337 posts
Joined: June 2013
Offline
jsmack
Well, it's using float math, what do you expect? You would need infinite precision to get exactly 0. Make transform gets around this by special casing since it takes degrees as input.

I just wanted to understand why quaternion was doing one thing and maketransform was doing another thing. You mentioned special casing, I suspect so, but where did you check that?

Also wanted to understand why PI is not the same value as radians(180), cause I was using fractions of PI constant to get certain angles and was wondering if there's something I should look out for, since I have both options available.

Thanks
User Avatar
Member
8531 posts
Joined: July 2007
Online
probiner
Also wanted to understand why PI is not the same value as radians(180), cause I was using fractions of PI constant to get certain angles and was wondering if there's something I should look out for, since I have both options available.

if you make sure you are using 64bit precision, both seem to be the same: 3.1415926000000001
which already reveals that PI houdini uses is barely 6 decimal points (and the 7th is for some reason rounded in opposite way)

if you use: 3.14159265358979323846264338327950288419716939937510
in your code (with 64bit precision) you will get much closer, but still not exact, since it's still just a floating point math
Edited by tamte - July 31, 2022 19:08:33
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
337 posts
Joined: June 2013
Offline
tamte
probiner
Also wanted to understand why PI is not the same value as radians(180), cause I was using fractions of PI constant to get certain angles and was wondering if there's something I should look out for, since I have both options available.

if you make sure you are using 64bit precision, both seem to be the same: 3.1415926000000001
which already reveals that PI houdini uses is barely 6 decimal points (and the 7th is for some reason rounded in opposite way)

if you use: 3.14159265358979323846264338327950288419716939937510
in your code (with 64bit precision) you will get much closer, but still not exact, since it's still just a floating point math

Hi Tomas

Thanks for looking into this. Indeed at 64bit they return as equal and interesting you find out the underused decimal places.
I'll toy more with this and report if I find anything interesting.

Cheers
  • Quick Links