谷歌地图两个圆的交点

Google Maps Two Circles Intersection Points(谷歌地图两个圆的交点)
本文介绍了谷歌地图两个圆的交点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

有没有一种简单的方法来获取两个

var R = 6371;//公里var dLat = (lat2-lat1).toRad();var dLon = (lon2-lon1).toRad();var lat1 = lat1.toRad();var lat2 = lat2.toRad();var a = Math.sin(dLat/2) * Math.sin(dLat/2) +Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));

和我们的

AC = c/2

如果给定的圆半径Rd是公里,那么

AB = Rd/R = Rd/6371

现在我们可以找到角度了

A = arccos(tg(AC) * ctg(AB))

起始方位(AF方向):

var y = Math.sin(dLon) * Math.cos(lat2);var x = Math.cos(lat1)*Math.sin(lat2) -Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);var brng = Math.atan2(y, x);

交叉点的方位:

B_bearing = brng - AD_轴承 = brng + A

交点坐标:

var latB = Math.asin( Math.sin(lat1)*Math.cos(Rd/R) +Math.cos(lat1)*Math.sin(Rd/R)*Math.cos(B_bearing));var lonB = lon1.toRad() + Math.atan2(Math.sin(B_bearing)*Math.sin(Rd/R)*Math.cos(lat1),Math.cos(Rd/R)-Math.sin(lat1)*Math.sin(lat2));

同样适用于 D_bearing

latB, lonB 以弧度为单位

Is there an easy way to get the lat/lng of the intersection points (if available) of two circles in Google Maps API V3? Or should I go with the hard way?

EDIT : In my problem, circles always have the same radius, in case that makes the solution easier.

解决方案

Yes, for equal circles rather simple solution could be elaborated:
Let's first circle center is A point, second circle center is F, midpoint is C, and intersection points are B,D. ABC is right-angle spherical triangle with right angle C.

We want to find angle A - this is deviation angle from A-F direction. Spherical trigonometry (Napier's rules for right spherical triangles) gives us formula:

cos(A)= tg(AC) * ctg(AB) where one symbol denote spherical angle, double symbols denote great circle arcs' angles (AB, AC). We can see that AB = circle radius (in radians, of course), AC = half-distance between A and F on the great circle arc. To find AC (and other values) - I'll use code from this excellent page

var R = 6371; // km
var dLat = (lat2-lat1).toRad();
var dLon = (lon2-lon1).toRad();
var lat1 = lat1.toRad();
var lat2 = lat2.toRad();

var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
        Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2); 
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 

and our

AC = c/2

If circle radius Rd is given is kilometers, then

AB = Rd / R = Rd / 6371

Now we can find angle

A = arccos(tg(AC) * ctg(AB))

Starting bearing (AF direction):

var y = Math.sin(dLon) * Math.cos(lat2);
var x = Math.cos(lat1)*Math.sin(lat2) -
        Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);
var brng = Math.atan2(y, x);

Intersection points' bearings:

B_bearing = brng - A
D_bearing = brng + A

Intersection points' coordinates:

var latB = Math.asin( Math.sin(lat1)*Math.cos(Rd/R) + 
              Math.cos(lat1)*Math.sin(Rd/R)*Math.cos(B_bearing) );
var lonB = lon1.toRad() + Math.atan2(Math.sin(B_bearing)*Math.sin(Rd/R)*Math.cos(lat1), 
                     Math.cos(Rd/R)-Math.sin(lat1)*Math.sin(lat2));

and the same for D_bearing

latB, lonB are in radians

这篇关于谷歌地图两个圆的交点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How do I can get a text of all the cells of the table using testcafe(如何使用 testcafe 获取表格中所有单元格的文本)
node_modules is not recognized as an internal or external command(node_modules 未被识别为内部或外部命令)
How can I create conditional test cases using Protractor?(如何使用 Protractor 创建条件测试用例?)
PhantomJS and clicking a form button(PhantomJS 并单击表单按钮)
Clicking #39;OK#39; on alert or confirm dialog through jquery/javascript?(在警报上单击“确定或通过 jquery/javascript 确认对话框?)
QunitJS-Tests don#39;t start: PhantomJS timed out, possibly due to a missing QUnit start() call(QunitJS-Tests 不启动:PhantomJS 超时,可能是由于缺少 QUnit start() 调用)