 # Pedro Alpiarça dos Santos

probiner

Expertise
Technical Director
Location
Portugal
Website

## Recent Forum Posts

#### Quaternion precision problem?Aug. 1, 2022, 6:58 a.m.

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

#### Quaternion precision problem?July 31, 2022, 4:53 p.m.

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

#### Quaternion precision problem?July 31, 2022, 6:22 a.m.

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) == PI`outputs `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) ;
```