0
私はこのpageに見つかったpythonの次のコードを適合させました: 相当のJavascriptに対応しました。なぜ私はJavascriptで楕円形を与えるサークルのこの数式ですか、Pythonの円ですか?
import math
# inputs
radius = 1000.0 # m - the following code is an approximation that stays reasonably accurate for distances < 100km
centerLat = 30.0 # latitude of circle center, decimal degrees
centerLon = -100.0 # Longitude of circle center, decimal degrees
# parameters
N = 10 # number of discrete sample points to be generated along the circle
# generate points
circlePoints = []
for k in xrange(N):
# compute
angle = math.pi*2*k/N
dx = radius*math.cos(angle)
dy = radius*math.sin(angle)
point = {}
point['lat']=centerLat + (180/math.pi)*(dy/6378137)
point['lon']=centerLon + (180/math.pi)*(dx/6378137)/math.cos(centerLat*math.pi/180)
# add to list
circlePoints.append(point)
print circlePoints
これらのポイント間の距離は、一定である必要があります。
私のJSのバージョンは同等、私の知る限り、次のとおりです。
var nodesCount = 8;
var coords = [];
for (var i = 0; i <= nodesCount; i++) {
var radius = 1000;
var angle = Math.PI*2*i/nodesCount;
var dx = radius*Math.cos(angle);
var dy = radius*Math.sin(angle);
coords.push([(rootLongitude + (180/Math.PI) * (dx/EARTH_RADIUS)/Math.cos(rootLatitude * Math.PI/180)),(rootLatitude + (180/Math.PI) * (dy/EARTH_RADIUS))]);
}
しかし、ときに私は出力これを、座標が中心から等距離ではありません。
これは非常にイライラしています。私はこれを1日デバッグしようとしていました。誰でもJSコードが失敗するのを見ることができますか?