source: trunk/MagicSoft/slalib/dsep.c@ 9990

Last change on this file since 9990 was 731, checked in by tbretz, 24 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 1.1 KB
Line 
1#include "slalib.h"
2#include "slamac.h"
3double slaDsep ( double a1, double b1, double a2, double b2 )
4/*
5** - - - - - - - -
6** s l a D s e p
7** - - - - - - - -
8**
9** Angle between two points on a sphere.
10**
11** (double precision)
12**
13** Given:
14** a1,b1 double spherical coordinates of one point
15** a2,b2 double spherical coordinates of the other point
16**
17** (The spherical coordinates are RA,dec, long,lat etc, in radians.)
18**
19** The result is the angle, in radians, between the two points. It
20** is always positive.
21**
22** Called: slaDcs2c
23**
24** Last revision: 5 October 1994
25**
26** Copyright P.T.Wallace. All rights reserved.
27*/
28{
29 int i;
30 double d, v1[3], v2[3], s2, c2;
31
32/* Convert coordinates from spherical to Cartesian */
33 slaDcs2c ( a1, b1, v1 );
34 slaDcs2c ( a2, b2, v2 );
35
36/* Modulus squared of half the difference vector */
37 s2 = 0.0;
38 for ( i = 0; i < 3; i++ ) {
39 d = v1[i] - v2[i];
40 s2 += d * d;
41 }
42 s2 /= 4.0;
43
44/* Angle between the vectors */
45 c2 = 1.0 - s2;
46 return 2.0 * atan2 ( sqrt ( s2 ), sqrt ( gmax ( 0.0, c2 )));
47}
Note: See TracBrowser for help on using the repository browser.