wcslib (8.2.2)

(root)/
include/
wcslib-8.2.2/
wcstrig.h
       1  /*============================================================================
       2    WCSLIB 8.2 - an implementation of the FITS WCS standard.
       3    Copyright (C) 1995-2023, Mark Calabretta
       4  
       5    This file is part of WCSLIB.
       6  
       7    WCSLIB is free software: you can redistribute it and/or modify it under the
       8    terms of the GNU Lesser General Public License as published by the Free
       9    Software Foundation, either version 3 of the License, or (at your option)
      10    any later version.
      11  
      12    WCSLIB is distributed in the hope that it will be useful, but WITHOUT ANY
      13    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      14    FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
      15    more details.
      16  
      17    You should have received a copy of the GNU Lesser General Public License
      18    along with WCSLIB.  If not, see http://www.gnu.org/licenses.
      19  
      20    Author: Mark Calabretta, Australia Telescope National Facility, CSIRO.
      21    http://www.atnf.csiro.au/people/Mark.Calabretta
      22    $Id: wcstrig.h,v 8.2.1.1 2023/11/16 10:05:57 mcalabre Exp mcalabre $
      23  *=============================================================================
      24  *
      25  * WCSLIB 8.2 - C routines that implement the FITS World Coordinate System
      26  * (WCS) standard.  Refer to the README file provided with WCSLIB for an
      27  * overview of the library.
      28  *
      29  *
      30  * Summary of the wcstrig routines
      31  * -------------------------------
      32  * When dealing with celestial coordinate systems and spherical projections
      33  * (some moreso than others) it is often desirable to use an angular measure
      34  * that provides an exact representation of the latitude of the north or south
      35  * pole.  The WCSLIB routines use the following trigonometric functions that
      36  * take or return angles in degrees:
      37  *
      38  *   - cosd()
      39  *   - sind()
      40  *   - tand()
      41  *   - acosd()
      42  *   - asind()
      43  *   - atand()
      44  *   - atan2d()
      45  *   - sincosd()
      46  *
      47  * These "trigd" routines are expected to handle angles that are a multiple of
      48  * 90 degrees returning an exact result.  Some C implementations provide these
      49  * as part of a system library and in such cases it may (or may not!) be
      50  * preferable to use them.  WCSLIB provides wrappers on the standard trig
      51  * functions based on radian measure, adding tests for multiples of 90 degrees.
      52  *
      53  * However, wcstrig.h also provides the choice of using preprocessor macro
      54  * implementations of the trigd functions that don't test for multiples of
      55  * 90 degrees (compile with -DWCSTRIG_MACRO).  These are typically 20% faster
      56  * but may lead to problems near the poles.
      57  *
      58  *
      59  * cosd() - Cosine of an angle in degrees
      60  * --------------------------------------
      61  * cosd() returns the cosine of an angle given in degrees.
      62  *
      63  * Given:
      64  *   angle     double    [deg].
      65  *
      66  * Function return value:
      67  *             double    Cosine of the angle.
      68  *
      69  *
      70  * sind() - Sine of an angle in degrees
      71  * ------------------------------------
      72  * sind() returns the sine of an angle given in degrees.
      73  *
      74  * Given:
      75  *   angle     double    [deg].
      76  *
      77  * Function return value:
      78  *             double    Sine of the angle.
      79  *
      80  *
      81  * sincosd() - Sine and cosine of an angle in degrees
      82  * --------------------------------------------------
      83  * sincosd() returns the sine and cosine of an angle given in degrees.
      84  *
      85  * Given:
      86  *   angle     double    [deg].
      87  *
      88  * Returned:
      89  *   sin       *double   Sine of the angle.
      90  *
      91  *   cos       *double   Cosine of the angle.
      92  *
      93  * Function return value:
      94  *             void
      95  *
      96  *
      97  * tand() - Tangent of an angle in degrees
      98  * ---------------------------------------
      99  * tand() returns the tangent of an angle given in degrees.
     100  *
     101  * Given:
     102  *   angle     double    [deg].
     103  *
     104  * Function return value:
     105  *             double    Tangent of the angle.
     106  *
     107  *
     108  * acosd() - Inverse cosine, returning angle in degrees
     109  * ----------------------------------------------------
     110  * acosd() returns the inverse cosine in degrees.
     111  *
     112  * Given:
     113  *   x         double    in the range [-1,1].
     114  *
     115  * Function return value:
     116  *             double    Inverse cosine of x [deg].
     117  *
     118  *
     119  * asind() - Inverse sine, returning angle in degrees
     120  * --------------------------------------------------
     121  * asind() returns the inverse sine in degrees.
     122  *
     123  * Given:
     124  *   y         double    in the range [-1,1].
     125  *
     126  * Function return value:
     127  *             double    Inverse sine of y [deg].
     128  *
     129  *
     130  * atand() - Inverse tangent, returning angle in degrees
     131  * -----------------------------------------------------
     132  * atand() returns the inverse tangent in degrees.
     133  *
     134  * Given:
     135  *   s         double
     136  *
     137  * Function return value:
     138  *             double    Inverse tangent of s [deg].
     139  *
     140  *
     141  * atan2d() - Polar angle of (x,y), in degrees
     142  * -------------------------------------------
     143  * atan2d() returns the polar angle, beta, in degrees, of polar coordinates
     144  * (rho,beta) corresponding to Cartesian coordinates (x,y).  It is equivalent
     145  * to the arg(x,y) function of WCS Paper II, though with transposed arguments.
     146  *
     147  * Given:
     148  *   y         double    Cartesian y-coordinate.
     149  *
     150  *   x         double    Cartesian x-coordinate.
     151  *
     152  * Function return value:
     153  *             double    Polar angle of (x,y) [deg].
     154  *
     155  *===========================================================================*/
     156  
     157  #ifndef WCSLIB_WCSTRIG
     158  #define WCSLIB_WCSTRIG
     159  
     160  #include <math.h>
     161  
     162  #include "wcsconfig.h"
     163  
     164  #ifdef HAVE_SINCOS
     165    void sincos(double angle, double *sin, double *cos);
     166  #endif
     167  
     168  #ifdef __cplusplus
     169  extern "C" {
     170  #endif
     171  
     172  
     173  #ifdef WCSTRIG_MACRO
     174  
     175  // Macro implementation of the trigd functions.
     176  #include "wcsmath.h"
     177  
     178  #define cosd(X) cos((X)*D2R)
     179  #define sind(X) sin((X)*D2R)
     180  #define tand(X) tan((X)*D2R)
     181  #define acosd(X) acos(X)*R2D
     182  #define asind(X) asin(X)*R2D
     183  #define atand(X) atan(X)*R2D
     184  #define atan2d(Y,X) atan2(Y,X)*R2D
     185  #ifdef HAVE_SINCOS
     186    #define sincosd(X,S,C) sincos((X)*D2R,(S),(C))
     187  #else
     188    #define sincosd(X,S,C) *(S) = sin((X)*D2R); *(C) = cos((X)*D2R);
     189  #endif
     190  
     191  #else
     192  
     193  // Use WCSLIB wrappers or native trigd functions.
     194  
     195  double cosd(double angle);
     196  double sind(double angle);
     197  void sincosd(double angle, double *sin, double *cos);
     198  double tand(double angle);
     199  double acosd(double x);
     200  double asind(double y);
     201  double atand(double s);
     202  double atan2d(double y, double x);
     203  
     204  // Domain tolerance for asin() and acos() functions.
     205  #define WCSTRIG_TOL 1e-10
     206  
     207  #endif // WCSTRIG_MACRO
     208  
     209  
     210  #ifdef __cplusplus
     211  }
     212  #endif
     213  
     214  #endif // WCSLIB_WCSTRIG