source: trunk/MagicSoft/slalib/sep.c@ 9929

Last change on this file since 9929 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"
3float slaSep ( float a1, float b1, float a2, float b2 )
4/*
5** - - - - - - -
6** s l a S e p
7** - - - - - - -
8**
9** Angle between two points on a sphere.
10**
11** (single precision)
12**
13** Given:
14** a1,b1 float spherical coordinates of one point
15** a2,b2 float 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: slaCs2c
23**
24** Last revision: 5 October 1994
25**
26** Copyright P.T.Wallace. All rights reserved.
27*/
28{
29 int i;
30 float d, v1[3], v2[3], s2, c2;
31
32/* Convert coordinates from spherical to Cartesian */
33 slaCs2c ( a1, b1, v1 );
34 slaCs2c ( a2, b2, v2 );
35
36/* Modulus squared of half the difference vector */
37 s2 = 0.0f;
38 for ( i = 0; i < 3; i++ ) {
39 d = v1[i] - v2[i];
40 s2 += d * d;
41 }
42 s2 /= 4.0f;
43
44/* Angle between the vectors */
45 c2 = 1.0f - s2;
46 return (float)
47 ( 2.0 * atan2 ( sqrt ( s2 ), sqrt ( gmax ( 0.0f, c2 ) ) ) );
48}
Note: See TracBrowser for help on using the repository browser.