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 <lgirdwood@gmail.com> 17 */ 18 19 module nova.angular_separation; 20 21 import std.math; 22 import nova.angular_separation; 23 import nova.utility; 24 import nova.ln_types; 25 26 extern (C) { 27 28 /*! \fn double ln_get_angular_separation(struct ln_equ_posn* posn1, struct ln_equ_posn* posn2); 29 * \param posn1 Equatorial position of body 1 30 * \param posn2 Equatorial position of body 2 31 * \return Angular separation in degrees 32 * 33 * Calculates the angular separation of 2 bodies. 34 * This method was devised by Mr Thierry Pauwels of the 35 * Royal Observatory Belgium. 36 * 37 * Note that this function can be used with ecliptic coordinates 38 * as well, by replacing right ascension and declination with 39 * longitude and latitude respectively. 40 * 41 * From Meeus, Chap 17 page 115 42 */ 43 @nogc double ln_get_angular_separation(const ref ln_equ_posn posn1, 44 const ln_equ_posn* posn2) nothrow 45 { 46 double d; 47 double x,y,z; 48 double a1,a2,d1,d2; 49 50 /* covert to radians */ 51 a1 = ln_deg_to_rad(posn1.ra); 52 d1 = ln_deg_to_rad(posn1.dec); 53 a2 = ln_deg_to_rad(posn2.ra); 54 d2 = ln_deg_to_rad(posn2.dec); 55 56 x = (cos(d1) * sin(d2)) 57 - (sin(d1) * cos(d2) * cos(a2 - a1)); 58 y = cos(d2) * sin(a2 - a1); 59 z = (sin(d1) * sin(d2)) + (cos(d1) * cos(d2) * cos(a2 - a1)); 60 61 x = x * x; 62 y = y * y; 63 d = atan2(sqrt(x + y), z); 64 65 return ln_rad_to_deg(d); 66 } 67 68 /*! \fn double ln_get_rel_posn_angle(struct ln_equ_posn* posn1, struct ln_equ_posn* posn2); 69 * \param posn1 Equatorial position of body 1 70 * \param posn2 Equatorial position of body 2 71 * \return Position angle in degrees 72 * 73 * Calculates the relative position angle of a body with respect to another body. 74 * 75 * Relative position angle is where body 2 appears relative to body 1. 76 * That is, having found body 1 in the sky, your eyes track at the 77 * relative position angle to find body 2. North is 0° and the angle 78 * increases clockwise from north. 79 * 80 * From Meeus, Chap 17, page 116 81 */ 82 @nogc double ln_get_rel_posn_angle(const ref ln_equ_posn posn1, 83 const ref ln_equ_posn posn2) nothrow 84 { 85 double P; 86 double a1,a2,d1,d2; 87 double x,y; 88 89 /* covert to radians */ 90 a1 = ln_deg_to_rad(posn1.ra); 91 d1 = ln_deg_to_rad(posn1.dec); 92 a2 = ln_deg_to_rad(posn2.ra); 93 d2 = ln_deg_to_rad(posn2.dec); 94 95 y = sin(a1 - a2); 96 x = (cos(d2) * tan(d1)) - (sin(d2) * cos(a1 - a2)); 97 98 P = atan2(y, x); 99 return ln_rad_to_deg(P); 100 } 101 102 }