点C到大圆AB弧的距离不正确

huangapple go评论69阅读模式
英文:

Incorrect distance of point C from an arc AB on great circle

问题

以下是代码的翻译部分:

private static void pointToArcDistance(double thirdX, double thirdY, double startX, double startY, 
    double endX, double endY) {
    double R = 6371000; 
    double φ1 = startX * Math.PI / 180; 
    double φ2 = endX * Math.PI / 180;
    double Δφ = (endX - startX) * Math.PI / 180;
    double Δλ = (endY - startY) * Math.PI / 180;
    double a = Math.sin(Δφ / 2) * Math.sin(Δφ / 2) +
    Math.cos(φ1) * Math.cos(φ2) *
    Math.sin(Δλ / 2) * Math.sin(Δλ / 2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double d13 = R * c; // distance between start & endPoint in meters
    double brng12 = bearing(startX, startY, endX, endY);
    double brng13 = bearing(startX, startY, thirdX, thirdY);
    double δ13 = d13 / R;
    double dXt = Math.asin(Math.sin(δ13) * Math.sin(brng13 - brng12)) * R;
    System.out.println("切线距离(CD):" + dXt);
}

private static double bearing(double lat1, double long1, double lat2, double long2) {
    double y = Math.sin(long2 - long1) * Math.cos(lat2);
    double x = Math.cos(lat1) * Math.sin(lat2) -
    Math.sin(lat1) * Math.cos(lat2) * Math.cos(long2 - long1);
    double polarDegrees = toDegrees(Math.atan2(y, x));
    return polarDegrees < 0 ? polarDegrees + 360 : polarDegrees;
}
英文:

Im getting incorrect length of CD where D marks the projection of third point C on arc AB:

Input to above code::

startX,startY- start point's coordinates of the arc--> (48.1388, 11.54988)

endX,endY-end point's coordinates of arc--> (48.139, 11.54988)

thirdX,thirdY- coordinated of point C away from arc--> (48.1389, 11.5496)

dXt is coming to be -13.41654587971497 meters but the expected value is 31.16949

I've written the code based on the equations I found: here
I am unable to find the cause of incorrect value, please help.Thanks.

<pre><code>
private static void pointToArcDistance(double thirdX, double thirdY, double startX, double startY,
double endX, double endY) {
double R = 6371000;
double φ1 = startX * Math.PI / 180;
double φ2 = endX * Math.PI / 180;
double Δφ = (endX - startX) * Math.PI / 180;
double Δλ = (endY - startY) * Math.PI / 180;
double a = Math.sin(Δφ / 2) * Math.sin(Δφ / 2) +
Math.cos(φ1) * Math.cos(φ2) *
Math.sin(Δλ / 2) * Math.sin(Δλ / 2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
double d13 = R * c; // distance between start & endPoint in meters
double brng12 = bearing(startX, startY, endX, endY);
double brng13 = bearing(startX, startY, thirdX, thirdY);
double δ13 = d13 / R;
double dXt = Math.asin(Math.sin(δ13) * Math.sin(brng13 - brng12)) * R;
System.out.println("tangent distance(CD)::" + dXt);
}

private static double bearing(double lat1, double long1, double lat2, double long2) {
double y = Math.sin(long2 - long1) * Math.cos(lat2);
double x = Math.cos(lat1) * Math.sin(lat2) -
Math.sin(lat1) * Math.cos(lat2) * Math.cos(long2 - long1);
double polarDegrees = toDegrees(Math.atan2(y, x));
return polarDegrees &lt; 0 ? polarDegrees + 360 : polarDegrees;
}

</code></pre>

答案1

得分: 1

你在这里将弧度转换为角度:

double polarDegrees = toDegrees(Math.atan2(y, x));

但接下来的计算需要使用弧度。

所以只需移除 toDegrees

英文:

You transform radians to degrees here:

double polarDegrees = toDegrees(Math.atan2(y, x));

but the next calculations need radians.

So just remove toDegrees

答案2

得分: 0

找到点到弧的距离:

  1. 首先,找到弧所隐含的椭圆的中心
  2. 使用 atan2 计算点到弧的角度
  3. 使用 cos(angle) * r1、sin(angle) * r2 计算与椭圆的 x、y 截距
  4. 使用从 x、y 截距到点的距离公式计算距离
英文:

To find the distance from a point to an arc:

  1. First, find the center of the oval implied by the arc
  2. Find the angle to the point using atan2
  3. Find the x,y intercept with your oval using cos(angle) * r1, sin(angle) * r2
  4. Use the distance formula from the x,y intercept to the point

huangapple
  • 本文由 发表于 2020年9月28日 00:39:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/64090876.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定