Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 11661

Circle generator in PHP failing on international date line

$
0
0

I have a circle generator that draws a KML circle around lat and lon. It works fine for 99% of the coordinates I input, however if the location is close to the int'l date line it chokes on the drawing.I was wondering if anyone has dealt with this issue and could offer a solution.

Here is my loop, if I use the coordinates, I am using 19.282494,166.636650My radius is 1047NM around this point as it iterates around the point it crosses the int'l dateline. Here is the output at it seems to choke, as it passes thru 0 degrees and 180 degrees

<coordinates>166.63665,36.70122262,30 170.33929602,36.39506383,30 173.86075879,35.49288317,30 177.04308391,34.04103068,30 179.76710126,32.10928643,30 -178.04299159,29.78247231,30 -176.42417943,27.15263215,30 -175.38386586,24.31316399,30 -174.90965799,21.35519771,30 -174.97725208,18.36580524,30 -175.55559428,15.42737555,30 -176.60947581,12.617518,30 -178.10014056,10.00900144,30 -179.98458741,7.66939861,30 177.7857603,5.66025581,30 175.26638245,4.0357509,30 172.52041272,2.84094525,30 169.61836825,2.10986796,30 166.63665,1.86376538,30 163.65493175,2.10986796,30 160.75288728,2.84094525,30 158.00691755,4.0357509,30 155.4875397,5.66025581,30 153.25788741,7.66939861,30 151.37344056,10.00900144,30 149.88277581,12.617518,30 148.82889428,15.42737555,30 148.25055208,18.36580524,30 148.18295799,21.35519771,30 148.65716586,24.31316399,30 149.69747943,27.15263215,30 151.31629159,29.78247231,30 153.50619874,32.10928643,30 156.23021609,34.04103068,30 159.41254121,35.49288317,30 162.93400398,36.39506383,30 166.63665,36.70122262,30 </coordinates>
foreach($ap as $name){    $name=trim(strtoupper($name));    $circleLat = $airport[$name][0];    $circleLon = $airport[$name][1];    $circleRadius = $_GET['circleRadius']*1852;    $circlePrecision = mostPrecision($circleLat, $circleLon, $circleRadius);    $coordinatesList = "";    // Code based on Google Earth community posting by 'ink_polaroid'    // http://bbs.keyhole.com/ubb/showflat.php/Cat/0/Number/23634/an//page//vc/1    $num_points = 36;    $delta_pts = 360/$num_points;    // convert coordinates to radians    $lat = deg2rad(floatval($circleLat));    $lon = deg2rad(floatval($circleLon));    $d = $circleRadius;    $d_rad = $d/6378137; // convert dist to angular distance in radians    // loop around the compass, appending coordinates of each vertex    for($i=0; $i<=$num_points; $i++) {        $radial = deg2rad($i*$delta_pts);      $lat_rad = asin(sin($lat)*cos($d_rad) + cos($lat)*sin($d_rad)*cos($radial));      $dlon_rad = atan2(sin($radial)*sin($d_rad)*cos($lat), cos($d_rad)-sin($lat)*sin($lat_rad));      $lon_rad = fmod(($lon+$dlon_rad + M_PI), 2*M_PI) - M_PI;      $coordinatesList .= Round(rad2deg($lon_rad),$circlePrecision).",".Round(rad2deg($lat_rad),$circlePrecision).",30 ";    }

TIASteve


Viewing all articles
Browse latest Browse all 11661

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>