Ik wil een script hebben dat berekent of de zon op, of onder is. Na even zoeken had ik al wat bruikbaars gevonden, wel in een andere taal maar omzetten naar PHP was niet zoveel werk.
Ik kan er echter geen nuttige resultaten uit krijgen.
Ik heb de coordinaten van Rotterdam ingevuld, maar ik weet niet of ze wel in het juiste formaat zijn. En de zenith (zon's hoogste punt) op 95 gezet.
Ook weet ik niet wat er met afkortingen zoals UTC en UT wordt bedoeld of wat er met "potentially needs to be adjusted into the range" wordt bedoeld.
Zonsondergang is vandaag om 21:29, dus $LocalT moet rond de 9.5 liggen (denk ik).
Ik kan er echter geen nuttige resultaten uit krijgen.
Ik heb de coordinaten van Rotterdam ingevuld, maar ik weet niet of ze wel in het juiste formaat zijn. En de zenith (zon's hoogste punt) op 95 gezet.
Ook weet ik niet wat er met afkortingen zoals UTC en UT wordt bedoeld of wat er met "potentially needs to be adjusted into the range" wordt bedoeld.
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
| <?php /*Source: http://williams.best.vwh.net/sunrise_sunset_algorithm.htm Inputs: day, month, year: date of sunrise/sunset latitude, longitude: location for sunrise/sunset zenith: Sun's zenith for sunrise/sunset offical = 90 degrees 50' civil = 96 degrees nautical = 102 degrees astronomical = 108 degrees NOTE: longitude is positive for East and negative for West */ //tijdzone GMT +1.00 $localOffset = 1; //zon's hoogste punt $zenith = 95; //Locatie Rotterdam 51,55 N - 4,29 E $latitude = 51.55; $longitude = 4.29; //1. first calculate the day of the year //daar hebben we in PHP al een functie voor $N = date("z"); echo("N: ".$N."<br>"); //2. convert the longitude to hour value and calculate an approximate time $lngHour = $longitude / 15; //if rising time is desired: // $t = $N + ((6 - $lngHour) / 24); //if setting time is desired: $t = $N + ((18 - $lngHour) / 24); //3. calculate the Sun's mean anomaly $M = (0.9856 * $t) - 3.289; //4. calculate the Sun's true longitude $L = $M + (1.916 * sin($M)) + (0.020 * sin(2 * $M)) + 282.634; //NOTE: L potentially needs to be adjusted into the range [0,360) //by adding/subtracting 360 //5a. calculate the Sun's right ascension $RA = atan(0.91764 * tan($L)); //NOTE: RA potentially needs to be adjusted into the range [0,360) //by adding/subtracting 360 //5b. right ascension value needs to be in the same quadrant as L $Lquadrant = (floor($L / 90)) * 90; $RAquadrant = (floor($RA / 90)) * 90; $RA = $RA + ($Lquadrant - $RAquadrant); //5c. right ascension value needs to be converted into hours $RA = $RA / 15; echo("RA: ".$RA."<br>"); //6. calculate the Sun's declination $sinDec = 0.39782 * sin($L); $cosDec = cos(asin($sinDec)); //7a. calculate the Sun's local hour angle $cosH = (cos($zenith) - ($sinDec * sin($latitude))) / ($cosDec * cos($latitude)); echo("cosH: ".$cosH."<br>"); if($cosH > 1) {echo("De zon komt hier niet op<br>");} //the sun never rises on this location (on the specified date) if($cosH < -1) {echo("De zon gaat hier niet onder<br>");} //the sun never sets on this location (on the specified date) //7b. finish calculating H and convert into hours //if if rising time is desired: // $H = 360 - acos(cosH) //if setting time is desired: $H = acos($cosH); $H = $H / 15; //8. calculate local mean time of rising/setting $T = $H + $RA - (0.06571 * $t) - 6.622; //9. adjust back to UTC $UT = $T - $lngHour; //NOTE: UT potentially needs to be adjusted into the range [0,24) //by adding/subtracting 24 //10. convert UT value to local time zone of latitude/longitude $localT = $UT + $localOffset; echo("LocalT: ".$localT."<br>"); ?> |
Zonsondergang is vandaag om 21:29, dus $LocalT moet rond de 9.5 liggen (denk ik).
[ Voor 5% gewijzigd door Johnny op 03-08-2003 11:24 ]
Aan de inhoud van de bovenstaande tekst kunnen geen rechten worden ontleend, tenzij dit expliciet in dit bericht is verwoord.