表作成のコンピュータプログラム例を,以下に示す。
これは,html で実行する PHP プログラムである。
";
/* 公転角度の何度から何度までを表示するか */
$t_from_degree = 0;
$t_to_degree = 360;
/* 公転角度の何度おきに表示するか */
$t_u_degree = 5;
/* 緯度 */
$a_degree = 50;
/* t_pi, t_0 */
$sunrise_t_pi = 25;
$sunrise_t_0 = 155;
$sunset_t_pi = 205;
$sunset_t_0 = 335;
$midday_t_pi = 295;
$midday_t_0 = 65;
$midnight_t_pi =115;
$midnight_t_0 = 245;
/* t_pi, t_0 */
$t_pi[0] = $sunrise_t_pi;
$t_pi[1] = $midday_t_pi;
$t_pi[2] = $sunset_t_pi;
$t_pi[3] = $midnight_t_pi;
$t_0[0] = $sunrise_t_0;
$t_0[1] = $midday_t_0;
$t_0[2] = $sunset_t_0;
$t_0[3] = $midnight_t_0;
/* 表項目 */
print "
日の出・日の入りの年間変化表 (北緯 ".$a_degree." 度)
公転角度(τ) |
経度 |
時刻 |
日中時間 |
日の出 |
正午 |
日の入 |
日の出 |
日の入 |
午前+午後(分) |
午前/午後 |
";
/* 計算とレコード書き出し ******************************************************/
/* 自転軸の傾き */
$n_degree = 23.4;
$n_radian = deg2rad( $n_degree );
$n_s = sin( $n_radian );
$n_c = cos( $n_radian );
/* 緯度 */
$a_radian = deg2rad( $a_degree );
$a_s = sin( $a_radian );
$a_c = cos( $a_radian );
/************************** ループ *****************************************/
for( $i = 0; $i < 360; $i++ ){
$t = deg2rad( $i );
$t_s = sin( $t );
$t_c = cos( $t );
/******* 日の出・日の入の経度計算 ********/
$sunrise_x = ( - $n_s * $a_s * $t_s * $t_c
- $n_c * $t_c * sqrt( 1 - pow($n_s * $t_c, 2) - pow($a_s, 2) ) )
/ (1 - pow($n_s * $t_c, 2));
$sunset_x = ( - $n_s * $a_s * $t_s * $t_c
+ $n_c * $t_c * sqrt( 1 - pow($n_s * $t_c, 2) - pow($a_s, 2) ) )
/ (1 - pow($n_s * $t_c, 2));
$sunrise_b_c = $sunrise_x / $a_c;
$sunset_b_c = $sunset_x / $a_c;
$sunrise_b = acos( $sunrise_b_c );
$sunset_b = acos( $sunset_b_c );
/******* 正午の経度計算 ********/
$midday_x = ( $a_s * $n_s * $t_s * $t_c
+ $n_c * $t_s * sqrt( 1 - pow($n_s * $t_s, 2) - pow($a_s, 2) ) )
/ (1 - pow($n_s * $t_s, 2));
$midnight_x = ( $a_s * $n_s * $t_s * $t_c
- $n_c * $t_s * sqrt( 1 - pow($n_s * $t_s, 2) - pow($a_s, 2) ) )
/ (1 - pow($n_s * $t_s, 2));
$midday_b_c = $midday_x / $a_c;
$midnight_b_c = $midnight_x / $a_c;
$midday_b = acos( $midday_b_c );
$midnight_b = acos( $midnight_b_c );
/******* 余弦方程式の二つの解 (αと 2π−α) のうちから,適正な方を選択 ********/
if( $i == 0 ){
$midday_b = 2 * pi() - $midday_b;
$b_0[0] = $sunrise_b;
$b_0[1] = $midday_b;
$b_0[2] = $sunset_b;
$b_0[3] = $midnight_b;
$b[0] = $sunrise_b;
$b[1] = $midday_b;
$b[2] = $sunset_b;
$b[3] = $midnight_b;
}
else {
$b[0] = $sunrise_b;
$b[1] = $midday_b;
$b[2] = $sunset_b;
$b[3] = $midnight_b;
for( $j = 0; $j < 4; $j++ ){
$case = 0;
if( ( $i == $t_0[$j] ) || ( $i == $t_pi[$j] ) ){
if( $i == $t_0[$j] ){
$b[$j] = 0;
}
else{
$b[$j] = pi();
}
}
else {
if( ( 0 < $b_0[$j] ) && ( $b_0[$j] < pi() ) ){
if( $b_0[$j] < $b[$j] ){
if( $i < $t_pi[$j] ){
$case = 111;
}
else{
$case = 112;
}
}
else{
if( $i < $t_0[$j] ){
$case = 121;
}
else{
$case = 122;
}
}
}
else {
if( $b_0[$j] < 2 * pi() - $b[$j] ){
if( $i < $t_0[$j] ){
$case = 211;
}
else{
$case = 212;
}
}
else{
if( $i < $t_pi[$j] ){
$case = 221;
}
else{
$case = 222;
}
}
}
}
if( ( $case == 112 ) || ( $case == 121 ) || ( $case == 211 ) || ( $case == 222 ) ){
$b[$j] = 2 * pi() - $b[$j];
}
}
}
/******* レコード作成・書き出し *******************************************************/
if( ( $i >= $t_from_degree ) && ( $i < $t_to_degree ) ){
if( $i % $t_u_degree == 0 ){
/******* 時間計算 *************************************************/
$sunrise = rad2deg( $b[0] );
$midday = rad2deg( $b[1] );
$sunset = rad2deg( $b[2] );
$midnight = rad2deg( $b[3] );
if( $midday < $sunrise ){
$am = ( $midday + 360 ) - $sunrise;
}
else {
$am = $midday - $sunrise;
}
$am = round( ( $am / 360 ) * ( 24 * 60 ), 0);
$am1 = ( 60 * 12 ) - $am;
if( $midday > $sunset ){
$pm = ( $sunset + 360 ) - $midday;
}
else {
$pm = $sunset - $midday;
}
$pm = round( ( $pm / 360 ) * ( 24 * 60 ), 0);
$am_min = $am1 % 60;
$am_hour = ($am1 - $am_min ) / 60 ;
$pm_min = $pm % 60;
$pm_hour = 12 + ( ( $pm - $pm_min )/ 60 );
$am_pm_ratio = round( $am / $pm, 2);
$sunrise = round( $sunrise, 0 );
$midday = round( $midday, 0 );
$sunset = round( $sunset, 0 );
$midnight = round( $midnight, 0 );
/******* レコード (表の1行分) 書き出し ********************/
print "
".$i." |
".$sunrise." |
".$midday." |
".$sunset." |
".$am_hour.":".$am_min." |
".$pm_hour.":".$pm_min." |
".($am + $pm)." ( ".$am." + ".$pm." ) |
".$am_pm_ratio." |
";
}
}
}
print "
|