public software.sextractor

[/] [trunk/] [src/] [wcs/] [wcstrig.c] - Blame information for rev 235

Details | Compare with Previous | View Log

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