如何在地图上计算线段交点

编程入门 行业动态 更新时间:2024-10-27 00:29:49
本文介绍了如何在地图上计算线段交点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在谷歌地图中使用纬度/经度坐标。

我有两行:

行A:48.31508162629726,-2.591741396838972至48.40216156645915,-2.2218462112093404
  • 行B:48.383816077371215,-2.274292940053768至48.66103546935337,-1.7066197241571377
  • 然后,我们使用以下公式找出交叉点。

    var XAsum = A.LngStart - A.LngEnd; var XBsum = B.LngStart - B.LngEnd; var YAsum = A.LatStart - A.LatEnd; var YBsum = B.LatStart - B.LatEnd; var LineDenominator = XAsum * YBsum - YAsum * XBsum; if(LineDenominator == 0.0) return false; var a = A.LngStart * A.LatEnd - A.LatStart * A.LngEnd; var b = B.LngStart * B.LatEnd - B.LatStart * B.LngEnd; var x =(a * XBsum - b * XAsum)/ LineDenominator; var y =(a * YBsum - b * YAsum)/ LineDenominator;

    这告诉我,这些行确实是交叉的,并返回x和y值。

    但是,当绘制返回点时,它与实际交叉点偏移(不太多)。

    是否有我可以使用更好和一样快速的算法,这将使我返回正确的交点?

    需要快速迭代遍历大量的行(〜

    编辑:注意这是给我一个大约7.5米的错误偏移量

    解决方案

    我假设您使用的算法是在笛卡尔坐标系(即平面)上找到线路交叉点的算法。不幸的是,地球不是一个平面(甚至是球体),所以使用该算法会引入误差。 Google Maps使用椭球(特别是WGS84)近似地球表面,因此您需要一个算法来查找椭圆上弧线的交点。

    页面可能包含一些有用的信息: http:// mathhelpforum。 com / calculus / 90196-point-intersection-two-lines.html

    I am working with Latitude / Longitude coordinates in a google map.

    I have two lines :

    • Line A : 48.31508162629726, -2.591741396838972 to 48.40216156645915, -2.2218462112093404
    • Line B : 48.383816077371215, -2.274292940053768 to 48.66103546935337, -1.7066197241571377

    I then use the following formula to find the point where they cross.

    var XAsum = A.LngStart - A.LngEnd; var XBsum = B.LngStart - B.LngEnd; var YAsum = A.LatStart - A.LatEnd; var YBsum = B.LatStart - B.LatEnd; var LineDenominator = XAsum * YBsum - YAsum * XBsum; if(LineDenominator == 0.0) return false; var a = A.LngStart * A.LatEnd - A.LatStart * A.LngEnd; var b = B.LngStart * B.LatEnd - B.LatStart * B.LngEnd; var x = (a * XBsum - b * XAsum) / LineDenominator; var y = (a * YBsum - b * YAsum) / LineDenominator;

    This tells me that the lines do indeed cross and returns the x and y values.

    However, when I plot the returned point, it is offset (not much) from the real intersection.

    Is there a better and just as fast algorithm I could use which will return me the correct intersection point ?

    It needs to be fast as I am iterating over a large number of lines (~1000).

    EDIT : Note this is giving me an error offset of around 7.5 meters

    解决方案

    I'm assuming the algorithm you're using is the one for finding line intersections on a Cartesian coordinate system (i.e. a plane). Unfortunately, the earth is not a plane (or even a sphere) so using that algorithm will introduce error. Google Maps uses an ellipsoid (specifically WGS84) to approximate the surface of the earth, so you'll need an algorithm for finding the intersections of arcs on an ellipsoid.

    This page might contains some helpful information: mathhelpforum/calculus/90196-point-intersection-two-lines.html

    更多推荐

    如何在地图上计算线段交点

    本文发布于:2023-10-25 18:37:29,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1527760.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:线段   交点   在地   图上

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!