summaryrefslogtreecommitdiffstats
path: root/Sun.h
blob: 6fc7857df6ac157f586d67b1b37596380e867dc3 (plain)
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
#ifndef _SUN_H_
#define _SUN_H_

#include <math.h>

class Sun
{
  public:
    Sun(float latitude0): latitude(latitude0){};
    Sun(){};
    
    void setlatitude(float latitude0){latitude=latitude0;};
    
    float declination(int day) {return 23.4*sin(2*M_PI*(284+day+1)/365);}
    float hourangle(int time) {return 15*(time+1-12);}
    float elevationangle(int day, int time) {
      return asin(sin(declination(day)*M_PI/180)*
             sin(latitude*M_PI/180)+
             cos(hourangle(time)*M_PI/180)*
             cos(declination(day)*M_PI/180)*
             cos(latitude*M_PI/180))*180/M_PI;
    }
    float azimutangle(int day, int time){
      float tau = hourangle(time)*M_PI/180;
      float sin_tau = sin(tau);
      float cos_tau = cos(tau);
      float sin_phi = sin(latitude*M_PI/180);
      float cos_phi = cos(latitude*M_PI/180);
      float tan_dek = tan(declination(day)*M_PI/180);

      return atan2(sin_tau, cos_tau*sin_phi-tan_dek*cos_phi)*180/M_PI;
//      return asin(cos(declination(day))*sin(elevationangle(day, time))/cos(hourangle(time)));
    }
  private:
    float latitude;
};

#endif /* _SUN_H_ */