transformations: Prefer atan2() to avoid special cases

This simplifies the code and also avoid the equality check for
floating numbers.

../src/calculations/calculations_transformations.c: In function ‘picplanner_transform_rotational_to_horizontal’:
../src/calculations/calculations_transformations.c:202:14: warning: comparing floating-point with ‘==’ or ‘!=’ is unsafe [-Wfloat-equal]
  202 |   else if (x == 0 && y < 0)
      |              ^~
../src/calculations/calculations_transformations.c:204:14: warning: comparing floating-point with ‘==’ or ‘!=’ is unsafe [-Wfloat-equal]
  204 |   else if (x == 0 && y > 0)
      |              ^~
main
Evangelos Ribeiro Tzaras 2023-07-17 18:52:08 +02:00
rodzic 0c627b0e7f
commit 29c660af5e
1 zmienionych plików z 1 dodań i 12 usunięć

Wyświetl plik

@ -193,18 +193,7 @@ double
y = cos (declination) * sin (time_sidereal - right_ascension);
if (x < 0 && y <= 0)
azimuth = atan (y / x);
else if (x < 0 && y > 0)
azimuth = atan (y / x) + 2 * M_PI;
else if (x > 0)
azimuth = atan (y / x) + M_PI;
else if (x == 0 && y < 0)
azimuth = M_PI / 2;
else if (x == 0 && y > 0)
azimuth = -3 * M_PI / 2;
else
azimuth = 0;
azimuth = atan2 (y, x);
elevation = asin (sin (latitude) * sin (declination)
+ cos (latitude) * cos (declination) * cos (time_sidereal - right_ascension));