問題描述
我在地圖 [x1,y1] 中有一個給定的中心.從那個中心我畫一個半徑為 1 英里的圓.我需要在圓周圍再生成 8 個點,各個點到中心的距離應該是 1 英里,所以它們在圓的邊界上.我確實知道得到 x2, y2 的公式,但問題是它不適用于地球地圖,因為它不是一個完美的球體.
I have a given center in the map [x1,y1]. From that center I am drawing a circle with a 1 mile radius. I need to generate 8 more points around the circle, the distance between the individual points to center should be 1 mile, so they are on the circle bounds. I do know the formulas to get x2, y2 but the problem is it doesn't apply to earth's map since it isn't a perfect sphere.
我嘗試過使用 this,但沒有成功.
I've tried using this, but with no luck.
誰能指出我的某個地方,或者我弄錯了?
Could anyone point me somewhere or maybe I got this wrong ?
已解決!
所以仔細閱讀整個 Movable Type Scripts 我發現了這個(為了我的使用稍微修改了):
So reading carefully throughout Movable Type Scripts I found this (slightly modified for my use):
let getPoint = (distance, bearing, center) => {
let δ = Number(distance) / 6371e3;
let θ = Number(bearing).toRadians();
let φ1 = center[0].toRadians();
let λ1 = center[1].toRadians();
let sinφ1 = Math.sin(φ1), cosφ1 = Math.cos(φ1);
let sinδ = Math.sin(δ), cosδ = Math.cos(δ);
let sinθ = Math.sin(θ), cosθ = Math.cos(θ);
let sinφ2 = sinφ1*cosδ + cosφ1*sinδ*cosθ;
let φ2 = Math.asin(sinφ2);
let y = sinθ * sinδ * cosφ1;
let x = cosδ - sinφ1 * sinφ2;
let λ2 = λ1 + Math.atan2(y, x);
return [φ2.toDegrees(), (λ2.toDegrees()+540)%360-180];
};
它確實解決了我的問題.
It did solved my problem.
推薦答案
您正在嘗試解決所謂的 第一個(或直接的)大地測量問題.知道這個名字會讓你的研究更容易.
You are trying to solve what is known as the first (or direct) geodetic problem. Knowing this name will make your research easier.
正如如何使用 Leaflet" 和 "在給定起始坐標、方位角和距離的情況下查找目的地坐標",您在 javascript 中解決此問題的主要選項是 cheap-ruler 用于小(ish)區域和 greographiclib 適合遠距離.
As pointed out by the answers to "How to draw polyline perpendicular to another polyline using Leaflet" and "Find destination coordinates given starting coodinates, bearing, and distance", your main options to approach this problem in javascript are cheap-ruler for small(ish) areas and greographiclib for large distances.
cheap-ruler 往往非常快但不準確,geographiclib 往往較慢但非常準確.
cheap-ruler tends to be very fast but inaccurate, and geographiclib tends to be slower but very accurate.
您可能會發現其他實現,每個都有自己的妥協.大地測量學很難,所以 沒有一種真正的方法"來計算距離或方位角.
You might find other implementations, each with its own compromises. Geodesy is hard, so there is no "one true way" to calculate distances or azimuths.
這篇關于生成給定距離的坐標,距中心的角度的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!