public software.sextractor

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

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