多边形中的孔 [英] Holes in a Polygon

查看:163
本文介绍了多边形中的孔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先给那些想对我的低接受率评论的人... im new,让我休息一下。

我添加了这个多边形代码本网站:
http://www.geocodezip.com/v3_polygon_example_donut.html



虽然有一个问题,但半径不准确。所以如果我测量两个城市之间的距离,那么画出这个圆圈,它就会离开,并且圆圈越大越差。



有什么想法吗?

 < script type =text / javascript> 
函数drawCircle(point,radius,dir){
var d2r = Math.PI / 180; //度数为弧度
var r2d = 180 / Math.PI; //弧度度数
var earthsradius = 3959; // 3959是SM

var points = 1000中地球的半径;

//找到lat / lon中的raidus
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} //另外一个确保我们连接
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));
ey = point.lng()+(rlng * Math.cos(theta)); //中心a +半径x * cos(theta)
ex = point.lat()+(rlat * Math.sin(theta)); // center b + radius y * sin(theta)
extp.push(new google.maps.LatLng(ex,ey));
bounds.extend(extp [extp.length-1]);
}
// alert(extp.length);
返回extp;
}

var map = null;
var bounds = null;

函数initialize(){
var myOptions = {
zoom:10,
center:new google.maps.LatLng(29.10860062,-95.46209717),
mapTypeControl:true,
mapTypeControlOptions:{style:google.maps.MapTypeControlStyle.DROPDOWN_MENU},
navigationControl:true,
mapTypeId:google.maps.MapTypeId.TERRAIN
}
map = new google.maps.Map(document.getElementById(map_canvas),
myOptions);

bounds = new google.maps.LatLngBounds();

var donut = new google.maps.Polygon({
paths:[triangleCoords = [
new google.maps.LatLng(-87,120),
new google.maps.LatLng(-87,-87),
new google.maps.LatLng(-87,0)],
drawCircle(new google.maps.LatLng(29.10860062,-95.46209717) ,2000,-1)],;

strokeColor:#000000,
strokeOpacity:0.6,
strokeWeight:2,
fillColor:#999999 ,
fillOpacity:0.6
));
donut.setMap(map);

map.fitBounds(bounds);


< / script>


解决方案

圆形绘图程序可以通过使用计算中的轴承点计算找到http://www.movable-type.co.uk/scripts/latlong.html#destPoint



θ是方位(以弧度表示,从北方顺时针);
d / R是角距离(以弧度为单位),其中d是行驶的距离,R是地球的半径b
$ b

  Math2 ); 
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));

将所有内容转换为弧度并确保d和R都以相同的单位表示,一个像这样的圆圈绘制例程



$ p $ 函数drawCircle(point,radius,dir,addtoBounds){
var d2r = Math.PI / 180; //度数为弧度
var r2d = 180 / Math.PI; //弧度度数
var earthsradius = 6371000; // 3959是SM

var points = 1000中地球的半径;

//找到lat / lon中的raidus
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} //另外一个确保我们连接
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);
返回extp;
}

我在 http://www.acleach.me.uk/gmaps/v3/mapsearch.htm 中心位于CYQX和EINN还有另一个标记和一圈1715NM的半径(表示为3176180米)。其他圈子以500,1000,1500,2000和2500NM的半径被添加。



我还在这两点之间增加了测地线。这与预期的直角相交,这是检查圆圈计算的准确性。


First off to those that want to make a comment about my low acceptance rating...im new, give me a break.

I added this polygon code from this website: http://www.geocodezip.com/v3_polygon_example_donut.html

There is an issue though, the radius is not accurate. So if I measure the distance between 2 cities, then draw this circle, it is way off, and gets worse the larger the circle.

Any ideas?

<script type="text/javascript"> 
function drawCircle(point, radius, dir) { 
var d2r = Math.PI / 180;   // degrees to radians 
var r2d = 180 / Math.PI;   // radians to degrees 
var earthsradius = 3959; // 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)); 
  ey = point.lng() + (rlng * Math.cos(theta)); // center a + radius x * cos(theta) 
  ex = point.lat() + (rlat * Math.sin(theta)); // center b + radius y * sin(theta) 
  extp.push(new google.maps.LatLng(ex, ey)); 
  bounds.extend(extp[extp.length-1]);
   } 
   // alert(extp.length);
   return extp;
   }

    var map = null;
    var bounds = null;

    function initialize() {
  var myOptions = {
    zoom: 10,
    center: new google.maps.LatLng(29.10860062, -95.46209717),
    mapTypeControl: true,
    mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
    navigationControl: true,
    mapTypeId: google.maps.MapTypeId.TERRAIN
  }
  map = new google.maps.Map(document.getElementById("map_canvas"),
                            myOptions);

  bounds = new google.maps.LatLngBounds();

  var donut = new google.maps.Polygon({
             paths: [triangleCoords = [
                        new google.maps.LatLng(-87, 120), 
                        new google.maps.LatLng(-87, -87), 
                        new google.maps.LatLng(-87, 0)],
                     drawCircle(new google.maps.LatLng(29.10860062, -95.46209717), 2000, -1)],";

             strokeColor: "#000000",
             strokeOpacity: 0.6,
             strokeWeight: 2,
             fillColor: "#999999",
             fillOpacity: 0.6
 });
 donut.setMap(map);

 map.fitBounds(bounds);


</script> 

解决方案

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.

这篇关于多边形中的孔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆