1 /*
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2 of the License, or (at your option) any later version.
6 *
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 *
16 * Copyright (C) 2000 - 2005 Liam Girdwood
17 */
18
19 #include <math.h>
20 #include <libnova/angular_separation.h>
21 #include <libnova/utility.h>
22
23 /*! \fn double ln_get_angular_separation (struct ln_equ_posn* posn1, struct ln_equ_posn* posn2);
24 * \param posn1 Equatorial position of body 1
25 * \param posn2 Equatorial position of body 2
26 * \return Angular separation in degrees
27 *
28 * Calculates the angular separation of 2 bodies.
29 * This method was devised by Mr Thierry Pauwels of the
30 * Royal Observatory Belgium.
31 */
32 /* Chap 17 page 115 */
ln_get_angular_separation(struct ln_equ_posn * posn1,struct ln_equ_posn * posn2)33 double ln_get_angular_separation (struct ln_equ_posn* posn1, struct ln_equ_posn* posn2)
34 {
35 double d;
36 double x,y,z;
37 double a1,a2,d1,d2;
38
39 /* covert to radians */
40 a1 = ln_deg_to_rad(posn1->ra);
41 d1 = ln_deg_to_rad(posn1->dec);
42 a2 = ln_deg_to_rad(posn2->ra);
43 d2 = ln_deg_to_rad(posn2->dec);
44
45 x = (cos(d1) * sin (d2))
46 - (sin(d1) * cos(d2) * cos(a2 - a1));
47 y = cos(d2) * sin(a2 - a1);
48 z = (sin (d1) * sin (d2)) + (cos(d1) * cos(d2) * cos(a2 - a1));
49
50 x = x * x;
51 y = y * y;
52 d = atan2(sqrt(x + y), z);
53
54 return ln_rad_to_deg(d);
55 }
56
57 /*! \fn double ln_get_rel_posn_angle (struct ln_equ_posn* posn1, struct ln_equ_posn* posn2);
58 * \param posn1 Equatorial position of body 1
59 * \param posn2 Equatorial position of body 2
60 * \return Position angle in degrees
61 *
62 * Calculates the position angle of a body with respect to another body.
63 */
64 /* Chapt 17, page 116 */
ln_get_rel_posn_angle(struct ln_equ_posn * posn1,struct ln_equ_posn * posn2)65 double ln_get_rel_posn_angle (struct ln_equ_posn* posn1, struct ln_equ_posn* posn2)
66 {
67 double P;
68 double a1,a2,d1,d2;
69 double x,y;
70
71 /* covert to radians */
72 a1 = ln_deg_to_rad(posn1->ra);
73 d1 = ln_deg_to_rad(posn1->dec);
74 a2 = ln_deg_to_rad(posn2->ra);
75 d2 = ln_deg_to_rad(posn2->dec);
76
77 y = sin (a1 - a2);
78 x = (cos(d2) * tan(d1)) - (sin(d2) * cos(a1 - a2));
79
80 P = atan2(y, x);
81 return ln_rad_to_deg(P);
82 }
83