已知一点经纬度及与另一点距离和航向,求另一点经纬度

本文结合Vincenty公式计算椭圆形地球模型目标点的方法

  /**
      * 已知一点经纬度及与另一点距离和航向,求另一点经纬度
      *
      * @param lon  已知一点的经度
      * @param lat  已知一点的纬度
      * @param brng 已知一点与另一点的方向 (角度)
      * @param dist 已知一点与另一点的距离 :米
      * @return
      */
    def computerOffsetPosition(lon: Double,
                               lat: Double,
                               brng: Double,
                               dist: Double): (Double, Double) = {


      //1. Calculate the destination point useing Vincenty's formula.
      // 角度转弧度
      val lat1 = lat * math.Pi / 180
      val lon1 = lon * math.Pi / 180
      val brg = brng * math.Pi / 180


      // 扁率
      val flat = 298.257223563
      // 地球 半长轴
      val a = 6378137.0
      //地球 半短轴
      val b = 6356752.314245

      val f = 1 / flat
      val sb = math.sin(brg)
      val cb = math.cos(brg)
      val tu1 = (1 - f) * math.tan(lat1)
      val cu1 = 1 / math.sqrt((1 + tu1 * tu1))
      val su1 = tu1 * cu1
      val s2 = math.atan2(tu1, cb)
      val sa = cu1 * sb
      val csa = 1 - sa * sa
      val us = csa * (a * a - b * b) / (b * b)
      val A = 1 + us / 16384 * (4096 + us * (-768 + us * (320 - 175 * us)))
      val B = us / 1024 * (256 + us * (-128 + us * (74 - 47 * us)))
      var s1 = dist / (b * A)
      var s1p = 2 * math.Pi
      var cs1m = 0.0
      var ss1 = 0.0
      var cs1 = 0.0
      var ds1 = 0.0


      //
      while (math.abs(s1 - s1p) > 1e-12) {
        cs1m = math.cos(2 * s2 + s1)
        ss1 = math.sin(s1)
        cs1 = math.cos(s1)
        ds1 = B * ss1 * (cs1m + B / 4 * (cs1 * (-1 + 2 * cs1m * cs1m) - B / 6 * cs1m * (-3 + 4 * ss1 * ss1) * (-3 + 4 * cs1m * cs1m)))
        s1p = s1
        s1 = dist / (b * A) + ds1
      }


      val t = su1 * ss1 - cu1 * cs1 * cb
      val lat2 = math.atan2(su1 * cs1 + cu1 * ss1 * cb, (1 - f) * math.sqrt(sa * sa + t * t))
      val l2 = math.atan2(ss1 * sb, cu1 * cs1 - su1 * ss1 * cb)
      val c = f / 16 * csa * (4 + f * (4 - 3 * csa))
      val l = l2 - (1 - c) * f * sa * (s1 + c * ss1 * (cs1m + c * cs1 * (-1 + 2 * cs1m * cs1m)))
      val lon2 = lon1 + l

      (lon2 * 180 / math.Pi, lat2 * 180 / math.Pi)
    }

参考资料

http://www.movable-type.co.uk/scripts/latlong-vincenty.html
http://www.geomidpoint.com/destination/calculation.html

你可能感兴趣的:(已知一点经纬度及与另一点距离和航向,求另一点经纬度)