File: angles.c

package info (click to toggle)
astronomical-almanac 5.6-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 1,104 kB
  • ctags: 408
  • sloc: ansic: 14,727; makefile: 158; xml: 109; sh: 1
file content (54 lines) | stat: -rw-r--r-- 1,171 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

/* Sun - object - earth angles and distances.
 * q (object), e (earth), and p (q minus e) are input vectors.
 * The answers are posted in the following global locations:
 */

#include "kep.h"

double FAR SE;	/* earth-sun distance */
double FAR SO;	/* object-sun distance */
double FAR EO;	/* object-earth distance */

double FAR pq;	/* cosine of sun-object-earth angle */
double FAR ep;	/* -cosine of sun-earth-object angle */
double FAR qe;	/* cosine of earth-sun-object angle */


int angles( p, q, e )
double p[], q[], e[];
{
double a, b, s;
int i;

EO = 0.0;
SE = 0.0;
SO = 0.0;
pq = 0.0;
ep = 0.0;
qe = 0.0;
for( i=0; i<3; i++ )
	{
	a = e[i];
	b = q[i];
	s = p[i];
	EO += s * s;
	SE += a * a;
	SO += b * b;
	pq += s * b;
	ep += a * s;
	qe += b * a;
	}
EO = sqrt(EO); /* Distance between Earth and object */
SO = sqrt(SO); /* Sun - object */
SE = sqrt(SE); /* Sun - earth */
/* Avoid fatality: if object equals sun, SO is zero.  */
if( SO > 1.0e-12 )
	{
	pq /= EO*SO;	/* cosine of sun-object-earth */
	qe /= SO*SE;	/* cosine of earth-sun-object */
	}
ep /= SE*EO;	/* -cosine of sun-earth-object */
return(0);
}