我有点问题。我正在尝试使用Javascript和Google Maps API v2执行以下操作:
我可以使用遍布互联网的公式来绘制各个圆圈。我面临的问题是圈子必须:
A.是同心的,并且B.每个“象限”必须具有不同的半径,即NE,NW,SE和SW
我几乎在互联网上想到的任何地方都进行了搜索,并且没有办法如何做到这一点。显然有人之前已经这样做了,因此我在一个程序员论坛上提出这个问题。 :)
谢谢!
更新:我已经使用以下代码绘制出来,我认为每个点的坐标都是。对于下图:
这是使用以下JS获得的:
注意:此javascript来自(略微修改)以下网站,根据算法最终可能会得到更多答案:http://www.movable-type.co.uk/scripts/latlong.html
更新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;
}
更新3:我应该也指出这是一个地理坐标系(因为整个事情是热带气旋风半径),而不是笛卡尔坐标系。谢谢!
基本上,将圆计算为x,y =(cos(a),sin(a)),然后将半径(这两个项)乘以半径,该半径是角度的适当函数。我不太了解Javascript或谷歌地图,所以我将在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;
}
这导致以下结果: