1 /*============================================================================
2 *
3 * WCSLIB - an implementation of the FITS WCS proposal.
4 * Copyright (C) 1995-1999, Mark Calabretta
5 *
6 * This library is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Library General Public License as published
8 * by the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; if not, write to the Free Software Foundation,
18 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * Correspondence concerning WCSLIB may be directed to:
21 * Internet email: mcalabre@atnf.csiro.au
22 * Postal address: Dr. Mark Calabretta,
23 * Australia Telescope National Facility,
24 * P.O. Box 76,
25 * Epping, NSW, 2121,
26 * AUSTRALIA
27 *
28 *=============================================================================
29 *
30 * The functions defined herein are trigonometric or inverse trigonometric
31 * functions which take or return angular arguments in decimal degrees.
32 *
33 * $Id: wcstrig.c,v 1.1.1.1 2002/03/15 16:33:26 bertin Exp $
34 *---------------------------------------------------------------------------*/
35
36 #ifdef HAVE_CONFIG_H
37 #include "config.h"
38 #endif
39
40 #ifdef HAVE_MATHIMF_H
41 #include <mathimf.h>
42 #else
43 #include <math.h>
44 #endif
45 #include "wcstrig.h"
46
47 #ifndef PI /* EB 02/06/97 */
48 #define PI 3.141592653589793238462643
49 #endif /* EB 02/06/97 */
50 const double d2r = PI / 180.0;
51 const double r2d = 180.0 / PI;
52
53 #ifndef HAVE_MATHIMF_H
54
wcs_cosd(angle)55 double wcs_cosd(angle)
56
57 const double angle;
58
59 {
60 double resid;
61
62 resid = fabs(fmod(angle,360.0));
63 if (resid == 0.0) {
64 return 1.0;
65 } else if (resid == 90.0) {
66 return 0.0;
67 } else if (resid == 180.0) {
68 return -1.0;
69 } else if (resid == 270.0) {
70 return 0.0;
71 }
72
73 return cos(angle*d2r);
74 }
75
76 /*--------------------------------------------------------------------------*/
77
wcs_sind(angle)78 double wcs_sind(angle)
79
80 const double angle;
81
82 {
83 double resid;
84
85 resid = fmod(angle-90.0,360.0);
86 if (resid == 0.0) {
87 return 1.0;
88 } else if (resid == 90.0) {
89 return 0.0;
90 } else if (resid == 180.0) {
91 return -1.0;
92 } else if (resid == 270.0) {
93 return 0.0;
94 }
95
96 return sin(angle*d2r);
97 }
98
99 /*--------------------------------------------------------------------------*/
100
wcs_tand(angle)101 double wcs_tand(angle)
102
103 const double angle;
104
105 {
106 double resid;
107
108 resid = fmod(angle,360.0);
109 if (resid == 0.0 || fabs(resid) == 180.0) {
110 return 0.0;
111 } else if (resid == 45.0 || resid == 225.0) {
112 return 1.0;
113 } else if (resid == -135.0 || resid == -315.0) {
114 return -1.0;
115 }
116
117 return tan(angle*d2r);
118 }
119
120 /*--------------------------------------------------------------------------*/
121
wcs_acosd(v)122 double wcs_acosd(v)
123
124 const double v;
125
126 {
127 if (v >= 1.0) {
128 if (v-1.0 < WCSTRIG_TOL) return 0.0;
129 } else if (v == 0.0) {
130 return 90.0;
131 } else if (v <= -1.0) {
132 if (v+1.0 > -WCSTRIG_TOL) return 180.0;
133 }
134
135 return acos(v)*r2d;
136 }
137
138 /*--------------------------------------------------------------------------*/
139
wcs_asind(v)140 double wcs_asind(v)
141
142 const double v;
143
144 {
145 if (v <= -1.0) {
146 if (v+1.0 > -WCSTRIG_TOL) return -90.0;
147 } else if (v == 0.0) {
148 return 0.0;
149 } else if (v >= 1.0) {
150 if (v-1.0 < WCSTRIG_TOL) return 90.0;
151 }
152
153 return asin(v)*r2d;
154 }
155
156 /*--------------------------------------------------------------------------*/
157
wcs_atand(v)158 double wcs_atand(v)
159
160 const double v;
161
162 {
163 if (v == -1.0) {
164 return -45.0;
165 } else if (v == 0.0) {
166 return 0.0;
167 } else if (v == 1.0) {
168 return 45.0;
169 }
170
171 return atan(v)*r2d;
172 }
173
174 /*--------------------------------------------------------------------------*/
175
wcs_atan2d(y,x)176 double wcs_atan2d(y, x)
177
178 const double x, y;
179
180 {
181 if (y == 0.0) {
182 if (x >= 0.0) {
183 return 0.0;
184 } else if (x < 0.0) {
185 return 180.0;
186 }
187 } else if (x == 0.0) {
188 if (y > 0.0) {
189 return 90.0;
190 } else if (y < 0.0) {
191 return -90.0;
192 }
193 }
194
195 return atan2(y,x)*r2d;
196 }
197
198 #endif
199