Holes in a Polygon

落花浮王杯 提交于 2019-11-29 18:12:33

A better circle-drawing routine may be found by using the "point from bearing" calculations at http://www.movable-type.co.uk/scripts/latlong.html#destPoint

θ is the bearing (in radians, clockwise from north); d/R is the angular distance (in radians), where d is the distance travelled and R is the earth’s radius

var lat2 = Math.asin( Math.sin(lat1)*Math.cos(d/R) + 
              Math.cos(lat1)*Math.sin(d/R)*Math.cos(brng) );
var lon2 = lon1 + Math.atan2(Math.sin(brng)*Math.sin(d/R)*Math.cos(lat1), 
                     Math.cos(d/R)-Math.sin(lat1)*Math.sin(lat2));

Converting everything to radians and making sure that d and R are both expressed in the same units, we get a circle-drawing routine like this

function drawCircle(point, radius, dir, addtoBounds) { 
var d2r = Math.PI / 180;   // degrees to radians 
var r2d = 180 / Math.PI;   // radians to degrees 
var earthsradius = 6371000; // 3959 is the radius of the earth in SM

   var points = 1000; 

   // find the raidus in lat/lon 
   var rlat = (radius / earthsradius) * r2d; 
   var rlng = rlat / Math.cos(point.lat() * d2r); 


   var extp = new Array(); 
   if (dir==1)  {var start=0;var end=points+1} // one extra here makes sure we connect the
   else     {var start=points+1;var end=0}
   for (var i=start; (dir==1 ? i < end : i > end); i=i+dir)  
   { 
      var theta = Math.PI * (i / (points/2)); 
    var lat1=point.lat()*d2r;
    var lon1=point.lng()*d2r;
    var d=radius;
    var R=earthsradius;

    var ex = Math.asin( Math.sin(lat1)*Math.cos(d/R) + 
              Math.cos(lat1)*Math.sin(d/R)*Math.cos(theta) );
    var ey = lon1 + Math.atan2(Math.sin(theta)*Math.sin(d/R)*Math.cos(lat1), 
                     Math.cos(d/R)-Math.sin(lat1)*Math.sin(ex));
      extp.push(new google.maps.LatLng(ex*r2d, ey*r2d)); 
      if (addtoBounds) bounds.extend(extp[extp.length-1]);
   } 
   // alert(extp.length);
   return extp;
   }

I have an example at http://www.acleach.me.uk/gmaps/v3/mapsearch.htm where the centre is at CYQX and there's another marker at EINN and a circle of 1715NM radius (expressed as 3176180m). Other circles have been added at radii of 500, 1000, 1500, 2000 and 2500NM.

I've also added a geodesic line between the two points. This crosses the circles at right-angles as expected, which is a check on the accuracy of the circle calculation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!