source: branches/FACT++_part_filenames/pal/palDs2tp.c@ 18796

Last change on this file since 18796 was 18347, checked in by tbretz, 9 years ago
File size: 3.4 KB
Line 
1/*
2*+
3* Name:
4* palDs2tp
5
6* Purpose:
7* Spherical to tangent plane projection
8
9* Language:
10* Starlink ANSI C
11
12* Type of Module:
13* Library routine
14
15* Invocation:
16* palDs2tp( double ra, double dec, double raz, double decz,
17* double *xi, double *eta, int *j );
18
19* Arguments:
20* ra = double (Given)
21* RA spherical coordinate of point to be projected (radians)
22* dec = double (Given)
23* Dec spherical coordinate of point to be projected (radians)
24* raz = double (Given)
25* RA spherical coordinate of tangent point (radians)
26* decz = double (Given)
27* Dec spherical coordinate of tangent point (radians)
28* xi = double * (Returned)
29* First rectangular coordinate on tangent plane (radians)
30* eta = double * (Returned)
31* Second rectangular coordinate on tangent plane (radians)
32* j = int * (Returned)
33* status: 0 = OK, star on tangent plane
34* 1 = error, star too far from axis
35* 2 = error, antistar on tangent plane
36* 3 = error, antistar too far from axis
37
38* Description:
39* Projection of spherical coordinates onto tangent plane:
40* "gnomonic" projection - "standard coordinates"
41
42* Authors:
43* PTW: Pat Wallace (STFC)
44* TIMJ: Tim Jenness (JAC, Hawaii)
45* {enter_new_authors_here}
46
47* History:
48* 2012-02-08 (TIMJ):
49* Initial version with documentation taken from Fortran SLA
50* Adapted with permission from the Fortran SLALIB library.
51* {enter_further_changes_here}
52
53* Copyright:
54* Copyright (C) 1996 Rutherford Appleton Laboratory
55* Copyright (C) 2012 Science and Technology Facilities Council.
56* All Rights Reserved.
57
58* Licence:
59* This program is free software: you can redistribute it and/or
60* modify it under the terms of the GNU Lesser General Public
61* License as published by the Free Software Foundation, either
62* version 3 of the License, or (at your option) any later
63* version.
64*
65* This program is distributed in the hope that it will be useful,
66* but WITHOUT ANY WARRANTY; without even the implied warranty of
67* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
68* GNU Lesser General Public License for more details.
69*
70* You should have received a copy of the GNU Lesser General
71* License along with this program. If not, see
72* <http://www.gnu.org/licenses/>.
73
74* Bugs:
75* {note_any_bugs_here}
76*-
77*/
78
79#include "pal.h"
80#include <math.h>
81
82void
83palDs2tp ( double ra, double dec, double raz, double decz,
84 double *xi, double *eta, int *j ) {
85
86 const double TINY = 1.0e-6;
87
88 double cdec;
89 double sdec;
90 double radif;
91 double cdecz;
92 double denom;
93 double sdecz;
94 double cradif;
95 double sradif;
96
97 /* Trig functions */
98 sdecz = sin(decz);
99 sdec = sin(dec);
100 cdecz = cos(decz);
101 cdec = cos(dec);
102 radif = ra - raz;
103 sradif = sin(radif);
104 cradif = cos(radif);
105
106 /* Reciprocal of star vector length to tangent plane */
107 denom = sdec * sdecz + cdec * cdecz * cradif;
108
109 /* Handle vectors too far from axis */
110 if (denom > TINY) {
111 *j = 0;
112 } else if (denom >= 0.) {
113 *j = 1;
114 denom = TINY;
115 } else if (denom > -TINY) {
116 *j = 2;
117 denom = -TINY;
118 } else {
119 *j = 3;
120 }
121
122 /* Compute tangent plane coordinates (even in dubious cases) */
123 *xi = cdec * sradif / denom;
124 *eta = (sdec * cdecz - cdec * sdecz * cradif) / denom;
125
126 return;
127}
Note: See TracBrowser for help on using the repository browser.