我有点问题。我正在尝试使用 Javascript 和 Google Maps API v2 执行以下操作:
我可以使用在 Internet 上找到的公式很好地绘制单个圆圈。我面临的问题是圈子必须:
一个。保持同心,并且 B. 每个“象限”必须有不同的半径,即 NE、NW、SE 和 SW
我几乎在 Internet 上搜索了所有我能想到的地方,但没有想出如何做到这一点。显然以前有人这样做过,因此我为什么要在程序员论坛上提问。 :)
谢谢!
更新:我已经使用以下代码绘制出我认为每个点的坐标。对于下图:
这是使用以下 JS 获得的:
注意:此 javascript 来自(稍作修改)以下站点,该站点可能包含更多有关算法最终结果的答案:http://www.movable-type.co.uk/scripts/latlong.html
更新 2:我能够在 Google map 中找到它:
使用以下代码创建:
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)),然后将此(两项)乘以作为 Angular 适当函数的半径。我不太了解 Javascript 或 Google map ,所以我将使用 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()
我无法真正理解您的草图,所以我只是猜测数字。此外,我将最右边的两个象限设为相同,因为这就是您的情节的样子,但这当然是可选的。
关于javascript - 使用谷歌地图绘制不规则同心圆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1382394/