-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsun.cpp
More file actions
66 lines (49 loc) · 1.39 KB
/
sun.cpp
File metadata and controls
66 lines (49 loc) · 1.39 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
// ----------------------------------------------------------
// sun.cpp
// ----------------------------------------------------------
#include "sun.h"
const double M_PI = 3.14159265358979323846;
const double M_PI_2 = 1.57079632679489661923;
Sun::Sun()
: m_theta(0.0), m_phi(0.0)
{
}
Sun::~Sun() { }
void Sun::calculatePosition(double time,
double meridian,
double longitude,
double latitude,
int day)
{
// Example input data:
//
// June 21, 10:30 Eastern Standard Time
// Toronto, Ontario, CANADA
//
// time = 10.5
// meridian = 1.3788101
// longitude = 1.3852096
// latitude = 0.762127107
// day = 172
//
//
// See section 4.0.2.1 Sun for further details
//
double t, delta;
double A, B, C, D, E, F;
A = 4*M_PI*(day - 80) / 373;
B = 2*M_PI*(day - 8) / 355;
C = 2*M_PI*(day - 81) / 368;
t = time +
0.170*sin(A) -
0.129*sin(B) +
12*(meridian - longitude)/M_PI;
delta = 0.4093*sin(C);
D = M_PI*t/12;
E = sin(latitude)*sin(delta) -
cos(latitude)*cos(delta)*cos(D);
F = (-cos(delta)*sin(D))/(cos(latitude)*sin(delta) -
sin(latitude)*cos(delta)*cos(D));
m_theta = M_PI_2 - asin(E);
m_phi = atan(F);
}