代码之家  ›  专栏  ›  技术社区  ›  Josh Delsman

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

  •  8
  • Josh Delsman  · 技术社区  · 16 年前

    我有点问题。我正试图使用Javascript&;谷歌地图API v2:

    myhurricane.net - Wind Radii Profile

    我可以用互联网上找到的公式很好地画出单个圆圈。我面临的问题是,圆圈必须:

    我使用以下代码绘制出了我认为每个点的坐标。对于下图:

    snapshot-1252125257.781397

    这是使用以下JS获得的:

    http://gist.github.com/181290

    注意:此javascript来自(稍作修改)以下网站,该网站可能会提供更多关于算法最终内容的答案: http://www.movable-type.co.uk/scripts/latlong.html

    我在谷歌地图上找到了这个:

    Concentric Circles Progress

    使用以下代码创建:

    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: 我可能还应该指出,这是为了

    2 回复  |  直到 9 年前
        1
  •  6
  •   Glorfindel Doug L.    7 年前

    基本上,将圆计算为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()
    

    这给了 alt text

    我真的无法理解你的草图,所以我只是猜测了数字。此外,我将最右侧的两个象限设置为相同,因为这就是你的情节,但这当然是可选的。

        2
  •  4
  •   Community Mohan Dere    9 年前

    我想通了。这是最后的代码。也许它可以重构一点?

    // 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;
    }
    

    结果如下:

    New myhurricane.net - Wind Radii (Map View) New myhurricane.net - Wind Radii (Satellite View)