optimaze for: sin(atan()) and cost(atan()) on Android.

float YX = uv.y / uv.x;

float ATAN = atan(YX);

float SIN = sin(ATAN);

float COS = cos(ATAN);

what’s the best way to replace this functions, thanks!

optimaze for: sin(atan()) and cost(atan()) on Android.

float YX = uv.y / uv.x;

float ATAN = atan(YX);

float SIN = sin(ATAN);

float COS = cos(ATAN);

what’s the best way to replace this functions, thanks!

SIN = uv.y/length(uv.xy);

COS = uv.x/length(uv.xy);

watch for division by zero

1 Like

according to :

sin(atan(T)) = T / sqrt(1 + T * T);

cos(atan(T)) = 1 / sqrt(1 + T * T);

Thanks!

If `length(uv.xy)`

is zero, the angle is undefined and so are sin/cos/tan. Even the two-argument form `atan(uv.y,uv.x)`

(and `atan2()`

in C or C++) is undefined in that case.

1 Like

if use atan(uv.y, uv.x), also must check if(uv.x != 0.0), right?

No. The two-argument form will return ±π/2 if the first argument is non-zero and the second argument is zero. It will also get the quadrant correct, i.e. atan(-x,-y) isn’t the same as atan(x,y) (the two will differ by ±π).

According to the GLSL spec, atan(0,0) is undefined (the C and C++ standards actually define this case according to the signs of the arguments; -0.0 and +0.0 are distinct in those languages).

1 Like