Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用谷歌地图绘制不规则同心圆_Javascript_Algorithm_Maps_Geometry - Fatal编程技术网

Javascript 使用谷歌地图绘制不规则同心圆

Javascript 使用谷歌地图绘制不规则同心圆,javascript,algorithm,maps,geometry,Javascript,Algorithm,Maps,Geometry,我有点问题。我尝试使用Javascript和Google Maps API v2执行以下操作: 我可以用互联网上的公式画出各个圆圈。我面临的问题是,圆圈必须: A.同心,并且 B.每个“象限”必须有不同的半径,即东北、西北、东南和西南 我在互联网上搜索了几乎所有我能想到的地方,但却找不到方法。很明显,以前有人做过这件事,因此我在程序员论坛上提问的原因如下: 谢谢 更新:我用下面的代码画出了我认为每个点的坐标。对于以下图纸: 这是使用以下JS获得的: 注意:此javascript来自(稍加修

我有点问题。我尝试使用Javascript和Google Maps API v2执行以下操作:

我可以用互联网上的公式画出各个圆圈。我面临的问题是,圆圈必须:

A.同心,并且 B.每个“象限”必须有不同的半径,即东北、西北、东南和西南

我在互联网上搜索了几乎所有我能想到的地方,但却找不到方法。很明显,以前有人做过这件事,因此我在程序员论坛上提问的原因如下:

谢谢

更新:我用下面的代码画出了我认为每个点的坐标。对于以下图纸:

这是使用以下JS获得的:

注意:此javascript来自(稍加修改)以下站点,该站点可能包含更多关于算法最终结果的答案:

更新2:我可以在谷歌地图上找到这个:

使用以下代码创建:

var NEQ = [0, 90];
var SEQ = [90, 180];
var SWQ = [180, 270];
var NWQ = [270, 0];

// var centrePoint = new LatLon(25.0, -83.1);
// pointsForWindQuadrant(NEQ, centrePoint, 50);
function pointsForWindQuadrant(quadrantDegrees, centrePoint, radius){
  var points = [];

  // Points must be pushed into the array in order
  points.push(new google.maps.LatLng(centrePoint.lat, centrePoint.lon));

  for(i = quadrantDegrees[0]; i <= quadrantDegrees[1]; i++){
    var point = centrePoint.destPoint(i, radius * 1.85);
    points.push(new google.maps.LatLng(point.lat, point.lon)); // Radius should be in nautical miles from NHC
  }

  points.push(new google.maps.LatLng(centrePoint.lat, centrePoint.lon));

  return points;
}
var-NEQ=[0,90];
var-SEQ=[90180];
var-SWQ=[180270];
var-NWQ=[270,0];
//var centrePoint=新拉特隆(25.0,-83.1);
//四象限后的点(NEQ,中心点,50);
象限后的功能点(象限度、中心点、半径){
var点=[];
//必须按顺序将点推入阵列中
points.push(新的google.maps.LatLng(centrePoint.lat,centrePoint.lon));

对于(i=quadrantDegrees[0];i基本上,将圆计算为x,y=(cos(a),sin(a)),然后将其(两个项)乘以一个半径,该半径是角度的适当函数。我不太懂Javascript或Google maps,所以我将用Python来做这件事,希望从这一点可以清楚地看出

from pylab import *

def Rscale(a):
    if a>3*pi/2:  # lower right, and then work CW around the circle
        return 1.
    elif a>pi:  # lower left
        return .9
    elif a>pi/2:   # upper left
        return .8
    else:       # upper right
        return 1.

def step_circle(R):
    return array([(R*Rscale(a))*array([cos(a), sin(a)]) for a in arange(0, 2*pi, .001)])

for R in (.5, .7, .9):  # make three concentric circles
    c = step_circle(R)
    plot(c[:,0], c[:,1])

show()


我不能真正理解你的草图,所以我只是猜测数字。另外,我将最右边的两个象限设置为相同的,因为这就是你的绘图,但这当然是可选的。

我想出来了。这是最后的代码。也许可以重构一下

// Returns points for a wind field for a cyclone. Requires
// a LatLon centre point, and an array of wind radii, starting
// from the northeast quadrant (NEQ), i.e., [200, 200, 150, 175]
//
// Returns points to be used in a GPolyline object.
function pointsForWindQuadrant(centrePoint, radii){
  if(radii.length != 4){ return false; }

  var points = [];
  var angles = [0, 90, 180, 270];

  // For each angle 0, 90, 180, 270...
  for(a = 0; a < angles.length; a++){
    // For each individual angle within the range, create a point...
    for(i = angles[a]; i <= angles[a] + 90; i++){
      var point = centrePoint.destPoint(i, radii[a] * 1.85); // Radius should be in nautical miles from NHC
      points.push(new google.maps.LatLng(point.lat, point.lon));
    }
  }

  // Add the first point again, to be able to close the GPolyline
  var point = centrePoint.destPoint(0, radii[0] * 1.85);
  points.push(new google.maps.LatLng(point.lat, point.lon));

  return points;
}
//返回气旋风场的点。需要
//一个拉特隆中心点和一系列风半径,从
//从东北象限(NEQ),即[200200150175]
//
//返回要在GPolyline对象中使用的点。
功能点后象限(中心点、半径){
如果(半径长度!=4){返回false;}
var点=[];
变量角度=[0,90,180,270];
//对于每个角度0、90、180、270。。。
对于(a=0;a对于(i=angles[a];我正在计划制作麦田怪圈?是的,它是针对热带气旋,而不是麦田怪圈。)你可能会更好地重新定位这个问题,使其更不受语言和库的影响。你真的需要更多的算法,也许还需要定义一两个数据结构。一旦你有了这些,将其移植到JavaScript并将值传递到Google Maps API将是微不足道的。我添加了“geometry”和“circle”标记;这还不够吗?我会做得更多而不是更详细地讨论算法,或者我认为我需要什么。我对几何不是很感兴趣;)干杯!到目前为止你(自己)想出了什么主意?如果我们看到您尝试过谷歌以外的其他方法,可能会得到更多帮助。这看起来可能是正确答案,但在我知道我可以正确翻译之前,我无法确定。有JS和谷歌地图API经验的人愿意帮助翻译吗?