【问题标题】:Angle between three geolocations [duplicate]三个地理位置之间的角度[重复]
【发布时间】:2016-09-12 08:46:41
【问题描述】:

我需要计算三个地理位置之间的角度,其中两个始终相同,只有一个在变化(例如当用户走路时)。

第一个点是用户的起始位置。第二个点是用户的当前位置,所以一开始第一个点等于第二个点。第一个点和固定点总是相同的。我有每个点的纬度和经度。

我尝试使用这个公式:

double angle1 = Math.atan2(startingLocation.getLongitude() - destinationLocation.getLongitude(), startingLocation.getLatitude() - destinationLocation.getLatitude());
double angle2 = Math.atan2(currentLocation.getLongitude() - destinationLocation.getLongitude(), currentLocation.getLatitude() - destinationLocation.getLatitude());

return Math.toDegrees(angle1 - angle2);

但是例如,当第一个点 == 第二个点 i 时,除了度数为 0。但它给了我奇怪的结果,比如 176 度。问题出在哪里?

【问题讨论】:

  • @Sabish.M 我只借了这个话题的图。

标签: java android geolocation angle


【解决方案1】:

两条线之间的角度可以通过以下函数计算

public static double angleBetween2Lines(Line2D line1, Line2D line2)
{
    double angle1 = Math.atan2(line1.getY1() - line1.getY2(),
                           line1.getX1() - line1.getX2());
    double angle2 = Math.atan2(line2.getY1() - line2.getY2(),
                           line2.getX1() - line2.getX2());
    return angle1-angle2;
}

来源:Calculating the angle between two lines without having to calculate the slope? (Java)

如果你的起点是(x1,y1),终点是(x2,y2),固定点是(x3,y3),那么你应该使用

double angle1 = Math.atan2(y3-y1,x3-x1);
double angle2 = Math.atan2(y3-y2,x3-x2);
double result = angle1-angle2;

【讨论】:

  • 您的第二个解决方案是正确的。谢谢!
  • @TomTom : 不客气 :)
【解决方案2】:

使用这个

double theta = 180.0 / Math.PI * Math.atan2(x1 - x2, y1 - y2);

【讨论】:

  • 第三个地理位置怎么样?
  • 这是(a)仅代码解决方案,这是不好的做法,并且(b)如果不是不正确的话,显然是不完整的,因为它忽略了第三个位置的问题(正如@PoorDeveloper 指出的那样)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-14
  • 2014-05-10
  • 2011-12-28
  • 2011-07-03
相关资源
最近更新 更多