forked from javiermunozcano/SISIFO
/
SunPosition.php
66 lines (52 loc) · 1.41 KB
/
SunPosition.php
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
<?php
function SunPosition($delta, $w, $SITE, $TIME)
{
// Latitute, rad.
$lat = $SITE['lat'];
// Calculations
for ($d = 0; $d < $TIME['Ndays']; $d++)
{
for ($h = 0; $h < $TIME['Nsteps']; $h++)
{
// Cosines of the solar zenith angle
$costetazs[$d][$h] = sin($delta[$d]) * sin($lat) + cos($delta[$d]) * cos($lat) * cos($w[$d][$h]);
// Limitation of costetazs to positive values
if ($costetazs[$d][$h] < 0)
{
$costetazs[$d][$h] = 0;
}
// Solar altitude angle
$gammas[$d][$h] = asin($costetazs[$d][$h]);
// Solar zenith angle
$tetazs[$d][$h] = pi()/2 - $gammas[$d][$h];
// Cosines of solar azimuth angle
$cosfis[$d][$h] = ( $costetazs[$d][$h] * sin($lat) - sin($delta[$d]) ) * valueSign($lat) / ( cos($gammas[$d][$h]) * cos($lat) );
// Limitation of cosfis(h,d) to real values
if ($cosfis[$d][$h] > 1)
{
$cosfis[$d][$h] = 1;
}
elseif ($cosfis[$d][$h] < -1)
{
$cosfis[$d][$h] = -1;
}
// Solar azimuth angle (negative towards the east, in the morning, and positive
// towards the west, in the evening.
if ($w[$d][$h] < 0)
{
$fis[$d][$h] = -acos($cosfis[$d][$h]);
}
else
{
$fis[$d][$h] = acos($cosfis[$d][$h]);
}
}
}
return $SUNPOS = array(
'costetazs' => $costetazs,
'cosfis' => $cosfis,
'gammas' => $gammas,
'tetazs' => $tetazs,
'fis' => $fis);
}
?>