Robust atan(y,x) on GLSL for converting XY coordinate to angle

后端 未结 5 766
花落未央
花落未央 2021-02-02 16:34

In GLSL (specifically 3.00 that I\'m using), there are two versions of atan(): atan(y_over_x) can only return angles between -PI/2, PI/2, while

5条回答
  •  甜味超标
    2021-02-02 17:22

    A formula that gives an angle in the four quadrants for any value

    of coordinates x and y. For x=y=0 the result is undefined.

    f(x,y)=pi()-pi()/2*(1+sign(x))* (1-sign(y^2))-pi()/4*(2+sign(x))*sign(y)

       -sign(x*y)*atan((abs(x)-abs(y))/(abs(x)+abs(y))) 
    

提交回复
热议问题