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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
|
<? header ("Content-type: image/gif" );
// Run the elements math and output to a gif file // // ------------------------------ Constants --------------------------------------- // define ("earth_grav_const" , 3.986e5); // Earth's Gravitational Const. (Km^3/s^2) define ("eg_4pi" , 10096.66709265246); // Earth's Gravitational Const. / 4*pi^2 define ("sideral_day_sec" , 86164.0984); // One Earth Rotation in seconds define ("equatorial_radius", 6378.137); // WGS-84 define ("flattening" , 298.257223563); // 1/flattening per WGS-84 define ("ghaa_deg" , 99.4033); // The angle between the Greenwich meridian define ("date_of_GHAA" , "1/1/1990 00:00"); // and 'Aries' at this date in Degrees define ("Tropical_year" , 365.242197); // Tropical Year in days define ("c" , 2.99792458e5); // speed of light in Km/s
// The amount the earth rotates during the 3 minutes and 5.59 seconds // difference between the 24 hrs (Solar) day and the sidereal day $extra_earth_rot_per_day = (2 * M_PI) / Tropical_year; // The total earth rotation in one Solar Day = 1 sideral day + the above figure $earth_rot_rad_sec = ($extra_earth_rot_per_day + (2 * M_PI))/86400; // Earth Rotation Rate (radians/sec)
// The Data from the form is needed earlier since the time array will be inside the main loop
$observer_site = $_GET ['loc_name']; $observer_lat = $_GET ['loc_lat']; $observer_long = $_GET ['loc_lon']; $observer_alt = $_GET ['loc_alt']; $observer_alt = $observer_alt/1000; $observer_lat_sign = $_GET ['lat_menu']; $observer_long_sign = $_GET ['lon_menu']; if ($observer_lat_sign == South) $observer_lat = -$observer_lat; if ($observer_long_sign == West ) $observer_long = -$observer_long; $range_units = $_GET ['range_units']; $symbol_rate = $_GET ['sym_rate'];
$no_steps = $_GET ['steps']; $interval = $_GET ['interval']; $time_unit = $_GET ['time_units']; $sec_per_step = $interval * $time_unit; $no_steps = $no_steps + 1; // 2010.03.23 - we're plotting segments, we need n+1 points for n segments
// Observer's UNIT vector In Geocentric Equatorial Coordinates // These are NOT Inertial coordinates, they are referenced to Greenwich $obs_lat_rad = deg2rad($observer_lat); $obs_long_rad = deg2rad($observer_long);
$observer_up_x = cos($obs_lat_rad) * cos($obs_long_rad); $observer_up_y = cos($obs_lat_rad) * sin($obs_long_rad); $observer_up_z = sin($obs_lat_rad); $observer_east_x = -sin($obs_long_rad); $observer_east_y = cos($obs_long_rad); $observer_north_x= -sin($obs_lat_rad) * cos($obs_long_rad); $observer_north_y= -sin($obs_lat_rad) * sin($obs_long_rad); $observer_north_z= cos($obs_lat_rad);
//Observer's XYZ coordinates on the surface of the earth. $polar_radius = equatorial_radius * (1 - (1/flattening)); $rx = ( pow(equatorial_radius,2) / sqrt( (pow(equatorial_radius,2) * pow(cos($obs_lat_rad),2) + (pow($polar_radius,2) * pow(sin($obs_lat_rad ),2))))) + $observer_alt; $rz = ( pow($polar_radius,2) / sqrt( (pow(equatorial_radius,2) * pow(cos($obs_lat_rad),2) + (pow($polar_radius,2) * pow(sin($obs_lat_rad ),2))))) + $observer_alt; $observer_x = $observer_up_x * $rx; $observer_y = $observer_up_y * $rx; $observer_z = $observer_up_z * $rz;
$sat_no = $_GET ['sat_list']; $slist = $_GET ['list']; //$sat_no = $sat_no+1;
if ($slist == 1) $tle_data = fopen('geo.txt',"r"); if ($slist == 3) $tle_data = fopen('stations.txt',"r"); if ($slist == 2) $tle_data = fopen('visual.txt' ,"r");
// $tle_data = fopen ('geo.txt',"r"); // 2010.3.22 - Hosting disabled access to off-site files, TLE file now hard coded to 'geo.txt'
if (!tle_data) nofile($tle_url); if (!tle_data) return;
$no_of_sat=0;
while ((!feof ($tle_data)) and ($tle_data)) { $buffer1a = fgets($tle_data, 128); $buffer2a = fgets($tle_data, 128); $buffer3a = fgets($tle_data, 128); $raw_sat_ele[$no_of_sat] = array ('Name' => $buffer1a, 'line1' => $buffer2a, 'line2' => $buffer3a); $no_of_sat++; }
$tle_data = array_sort ($raw_sat_ele, 'Name');
$name = $tle_data[$sat_no]['Name']; $line1 = $tle_data[$sat_no]['line1']; $line2 = $tle_data[$sat_no]['line2'];
$sat_name = substr ($name, 0, 24 ); $sat_cata = substr ($line1, 2, 5 ); $sat_launch_year = substr ($line1, 9, 2 ); $sat_launch_no = substr ($line1, 11, 3 ); $sat_payload_no = substr ($line1, 14, 1 ); $epoch_year = substr ($line1, 18, 2 ); $epoch_sider_day = substr ($line1, 20, 3 ); $epoch_sider_time = substr ($line1, 23, 9 ); $sat_inclination = substr ($line2, 8, 8 ); $sat_ra_asc_node = substr ($line2, 17, 8 ); $sat_eccentricity = substr ($line2, 26, 7 ); $sat_arg_perigee = substr ($line2, 34, 8 ); $sat_mean_anomaly = substr ($line2, 43, 8 ); $sat_mean_motion = substr ($line2, 52, 11 ); $sat_rev_at_epoch = substr ($line2, 63, 5 );
// --------------------- resolve for given satellite number of steps -----------//
$max_az = 0; $min_az = 360; // used for calculating min and max $max_el = 0; $min_el = 90; //for the graph's scale
for ($step=0; $step<$no_steps; $step++) //-------------------------------------- // {
// Initializing the Current Date Array
$curr_date_array = getdate(time() + ($step * $sec_per_step)); $curr_year = $curr_date_array ['year']; $curr_day = $curr_date_array ['yday'] + 1; // php counts days from 0, TLE epoch counts from 1 $curr_sec =($curr_date_array ['hours'] * 3600) + ($curr_date_array ['minutes'] * 60) + $curr_date_array ['seconds']; // - 3600; // Misterious One Hour shift (20.10.03 - 26.10.03) Possible DST bug $curr_time_unix = $curr_date_array [0]; $curr_frac_day = $curr_sec / 86400; // This is how the sidereal time appears in the TLEs, fraction of solar day // Bringing the RA in sync with the current time. // Seconds since reference GHAA was specified $delta_ghaa_sec = $curr_time_unix - (strtotime (date_of_GHAA)); // time is in seconds since 1.1.70 (UNIX time)
// The current Angle to Aries from the Greenwich meridian. This is the X axis of the Geocentric Inetial coordinates $current_ghaa_rad = deg2rad(ghaa_deg) + ($delta_ghaa_sec * $earth_rot_rad_sec); $cos_ghaa = cos(-$current_ghaa_rad); $sin_ghaa = sin(-$current_ghaa_rad);
// Calculating elapsed time since epoch $ep_yr = $epoch_year; if ($ep_yr>60) $ep_yr = $ep_yr + 1900; if ($ep_yr<60) $ep_yr = $ep_yr + 2000; $ep_dy = $epoch_sider_day; $ep_tm = $epoch_sider_time; $ep_tm_sec = $ep_tm * 86400;
$ep_unix_y = getdate( mktime (0, 0, 0, 1, 1, $ep_yr) ); // Used to calculate time since epoch taking $ep_unix_s = $ep_unix_y[0] + (($ep_dy + $ep_tm) * 86400); // into account leap years
$delta_sec = $curr_time_unix - $ep_unix_s; $delta_frac_yr = $delta_sec / (86400 * Tropical_year);
// Calculating Axes of the elliptic orbit $mean_motion = $sat_mean_motion; // Mean Motion in the TLE is given in Revolution / Day $period = ( 1 / $mean_motion) * (24 * 60 * 60); // Aug 2017, use period for Solar day $eccentricity = $sat_eccentricity; $eccentricity = $eccentricity/1e7; // Eccentricity in the TLEs assumes decimal point $semi_major_axis = pow((eg_4pi*pow($period, 2)),(1/3)); $semi_minor_axis = $semi_major_axis * sqrt(1-pow($eccentricity,2));
// Find the 'Eccentric Anomaly' by iterating (Newton's Method) // Mean Anomaly = Ecc Anomaly - (Eccentricity * Sin (Ecc Anomaly)) $mean_mot_rad_sec = ($mean_motion * 2 * M_PI) / 86400; // Mean Motion in RAD / sec $mean_anomaly_deg = $sat_mean_anomaly; // Mean Anomaly in the TLE is given in Degrees $mean_anomaly_rad = deg2rad($mean_anomaly_deg); $rads_since_epoch = ($mean_mot_rad_sec * $delta_sec) + $mean_anomaly_rad; // (Mean Motion * Elapsed time) + Mean Anomaly $frac_rev = $rads_since_epoch - (2 * M_PI * ( floor( $rads_since_epoch / (2 * M_PI) ) ));
// Do the iterations with this initial value $ecc_an = $frac_rev; do { $cos_ea = cos ($ecc_an); $sin_ea = sin ($ecc_an); $denom = 1 - ($cos_ea * $eccentricity); $iter = ( $ecc_an - ( $eccentricity * $sin_ea) - $rads_since_epoch ) / $denom; $ecc_an = $ecc_an - $iter; } while (abs($iter) > 0.0000025);
$sat_range = $semi_major_axis * $denom; // Satellite range from the CENTER of the earth
// Calculating Satellite position vector on the Orbital Plane $sat_orb_plane_X = $semi_major_axis * ($cos_ea - $eccentricity); $sat_orb_plane_Y = $semi_minor_axis * $sin_ea;
// Partial Rotation Matrix to transform from the Orbital Plane to Inertial (Celestial) Coordinates $incl = $sat_inclination; $argpg = $sat_arg_perigee; $raan = $sat_ra_asc_node; $cos_arg_per = cos (deg2rad($argpg)); $sin_arg_per = sin (deg2rad($argpg)); $cos_raan = cos (deg2rad($raan)); $sin_raan = sin (deg2rad($raan)); $cos_incl = cos (deg2rad($incl)); $sin_incl = sin (deg2rad($incl));
$cel_x_x = ( $cos_arg_per * $cos_raan) - ($sin_arg_per * $sin_raan * $cos_incl); $cel_x_y = (-$sin_arg_per * $cos_raan) - ($cos_arg_per * $sin_raan * $cos_incl); $cel_y_x = ( $cos_arg_per * $sin_raan) + ($sin_arg_per * $cos_raan * $cos_incl); $cel_y_y = (-$sin_arg_per * $sin_raan) + ($cos_arg_per * $cos_raan * $cos_incl); $cel_z_x = ( $sin_arg_per * $sin_incl); $cel_z_y = ( $cos_arg_per * $sin_incl);
// Calculatins Satellite position vector in Celestial Coordinates $sat_celestial_X = ($sat_orb_plane_X * $cel_x_x) + ($sat_orb_plane_Y * $cel_x_y); $sat_celestial_Y = ($sat_orb_plane_X * $cel_y_x) + ($sat_orb_plane_Y * $cel_y_y); $sat_celestial_Z = ($sat_orb_plane_X * $cel_z_x) + ($sat_orb_plane_Y * $cel_z_y);
// Satellite Coordinates in Geocentric Equatorial Coordinates (from RA to LONG, etc.)
$sat_geoc_x = ( $sat_celestial_X * $cos_ghaa ) - ( $sat_celestial_Y * $sin_ghaa ); $sat_geoc_y = ( $sat_celestial_X * $sin_ghaa ) + ( $sat_celestial_Y * $cos_ghaa ); $sat_geoc_z = $sat_celestial_Z ;
// Calculate Subsatellite Point $sub_sat_long = rad2deg(atan2($sat_geoc_y, $sat_geoc_x)); // East / West $sub_sat_lat = rad2deg(asin ($sat_geoc_z/$sat_range )); // North / South
// Calculating Range Vector
$range_x = $sat_geoc_x - $observer_x; $range_y = $sat_geoc_y - $observer_y; $range_z = $sat_geoc_z - $observer_z; $range_magnitude = sqrt(pow($range_x,2)+pow($range_y,2)+pow($range_z,2)); $range_norm_x = $range_x / $range_magnitude; //Normalized Range Vector $range_norm_y = $range_y / $range_magnitude; $range_norm_z = $range_z / $range_magnitude;
$range_up = ($range_norm_x * $observer_up_x) + ($range_norm_y * $observer_up_y) + ($range_norm_z * $observer_up_z); $range_east = ($range_norm_x * $observer_east_x) + ($range_norm_y * $observer_east_y); $range_north= ($range_norm_x * $observer_north_x)+ ($range_norm_y * $observer_north_y) + ($range_norm_z * $observer_north_z);
// Calculating the Look Angles $obs_elevation = rad2deg(asin($range_up)); if ($obs_elevation < 0) {$obs_elevation = 0;} $obs_azimuth = rad2deg(atan2($range_east,$range_north)); if ( $obs_azimuth < 0 ) $obs_azimuth = 360 + $obs_azimuth; if ( $obs_azimuth >360) $obs_azimuth = $obs_azimuth % 360;
// Calculating the range according to the units // if ($range_units == 'Kilometers' ) $range_print = round ($range_magnitude,2); // if ($range_units == 'milliseconds' ) $range_print = round ((($range_magnitude * 1000) / c) , 2) ; // if ($range_units == 'symbols' ) $range_print = round ((($range_magnitude * 1000 * $symbol_rate) / c) , 2) ;
// -- Filling an Array with the results --
$results[$step] = array ('Az' => $obs_azimuth, 'El' => $obs_elevation );
if ($obs_azimuth >= $max_az) $max_az = $obs_azimuth; if ($obs_azimuth < $min_az) $min_az = $obs_azimuth; if ($obs_elevation >= $max_el) $max_el = $obs_elevation; if ($obs_elevation < $min_el) $min_el = $obs_elevation;
} // ----------------------- END of main Loop ------------------------------ //
// ----------------------- Graph the analema ------------------------------ //
$width = 460; $height = $width; $reduce = 0.85; $analema = imageCreate($width,$width); $color_bkg = imageColorAllocate($analema, 0, 0, 0); $color_plot= imageColorAllocate($analema, 255, 0, 0); $color_grid= imageColorAllocate($analema, 255,255,255); $colo2_plot= imageColorAllocate($analema, 0,255, 0);
imageFilledRectangle ($analema, 0, 0, $width-1, $height-1, $color_bkg);
imageLine ($analema , 0 , $height/2, $width , $height/2, $color_grid); imageLine ($analema , $width/2, 0, $width/2, $height , $color_grid); imageString ($analema , 5, 3, 3, "Analema for $sat_name", $color_grid);
$lon_pr = abs(round($observer_long,2)); $lat_pr = abs(round($observer_lat, 2));
if ($observer_lat_sign == North) $lat_pr .= " N"; if ($observer_lat_sign == South) $lat_pr .= " S"; if ($observer_long_sign == West) $lon_pr .= " W"; if ($observer_long_sign == East) $lon_pr .= " E";
imageString ($analema , 3, 4, 18, "Observed from $lat_pr $lon_pr", $color_grid);
$per_pr = round ((( $no_steps * $interval * $time_unit ) / 3600),1);
imageString ($analema , 2, 4, 30, "Period: $per_pr hr.", $color_grid);
// imageString ($analema , 2, 8, 40, "Min AZ $min_az Max AZ $max_az", $color_grid); // imageString ($analema , 2, 8, 50, "Min EL $min_el Max EL $max_el", $color_grid);
$az_origin = round (($min_az + (($max_az - $min_az)/2)),3); $el_origin = round (($min_el + (($max_el - $min_el)/2)),3);
$x_min = ($results[0]['Az']) - $az_origin; $x_max = $x_min + 0.01; $y_min = ($results[0]['El']) - $el_origin; $y_max = $y_min + 0.01;
for ($step=0; $step<($no_steps); $step++) // First pass to calculate scale {
$az_step = $results[$step]['Az']; $el_step = $results[$step]['El']; $x = ($az_step - $az_origin ); $y = ($el_step - $el_origin );
if ($x > $x_max) $x_max = $x; if ($x < $x_min) $x_min = $x; if ($y > $y_max) $y_max = $y; if ($y < $y_min) $y_min = $y;
$plot[$step] = array ('x' => $x, 'y' => $y ); }
$scale_x = $reduce * ($width / ( $x_max - $x_min )); //pixels per degree $scale_y = $reduce * ($height / ( $y_max - $y_min ));
// 2010.03.23 - using same scale for both axis
//imageString ($analema , 2, 8, 40, "scale $scale_x $scale_y", $color_grid);
if ($scale_x < $scale_y) {$scale_y=$scale_x;} else {$scale_x=$scale_y;}
//imageString ($analema , 2, 8, 50, "scale $scale_x_ratio $scale_y_ratio", $color_grid);
$min_az_pr = round ($az_origin - (($width /2)/$scale_x),2); $max_el_pr = round ($el_origin + (($height/2)/$scale_y),2);
imageString ($analema , 1, 3, $height - 15, "$min_az_pr", $color_grid); imageString ($analema , 1, ($width/2)+8, $height - 15, "$az_origin", $color_grid); imageString ($analema , 1, ($width-36), 3, "$max_el_pr", $color_grid); imageString ($analema , 1, ($width-36),($height/2)-15, "$el_origin", $color_grid);
for ($step=1; $step<$no_steps; $step++) { $x1 = ($width / 2) + ( ($plot[$step]['x']) * $scale_x ); $y1 = ($height / 2) - ( ($plot[$step]['y']) * $scale_y ); // Elevation was being plotted from as mirror, 0 on top $x0 = ($width / 2) + ( ($plot[$step-1]['x']) * $scale_x ); $y0 = ($height / 2) - ( ($plot[$step-1]['y']) * $scale_y );
//imageString ($analema, 3, 5, 90+($step*12), "x {$plot[$step]['x']} y {$plot[$step]['y']}", $colo2_plot);
if ( abs($x1-$x0) < ($width*0.52) ) {imageLine ($analema, $x0, $y0, $x1, $y1, $colo2_plot);
// imageLine ($analema, $x0, $y0, $x1, $y1, $color_plot); // $tmp_print=$x1-$x0; // imageString ($analema, 3, 5, 90+($step*12), "$tmp_print", $color_plot); } } imagefilledellipse ($analema, $x1, $y1, 6, 6, $color_plot); imageInterlace ($analema , 1); imageGIF ($analema );
function array_sort($array, $key) { for ($i = 0; $i < sizeof($array); $i++) { $sort_values[$i] = $array[$i][$key]; } asort ($sort_values); reset ($sort_values); while (list ($arr_key, $arr_val) = each ($sort_values))
{ $sorted_arr[] = $array[$arr_key]; } return $sorted_arr; } function rarray_sort($array, $key) { for ($i = 0; $i < sizeof($array); $i++) { $sort_values[$i] = $array[$i][$key]; } arsort ($sort_values); reset ($sort_values); while (list ($arr_key, $arr_val) = each ($sort_values)) { $sorted_arr[] = $array[$arr_key]; } return $sorted_arr; } ?>
|