问题描述
我得到的CD长度不正确,其中D标记了第三点C在弧AB上的投影:
输入上述代码:
startX,startY-圆弧的起点坐标->(48.1388,11.54988)
endX,endY端点的弧线坐标->(48.139,11.54988)
第三点X,第三点Y- C点远离圆弧->(48.1389,11.5496)
dXt将达到-13.41654587971497米,但预期值为31.16949
我已经根据发现的方程式编写了代码:here 我找不到导致值错误的原因,请帮忙。谢谢。
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,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
解决方法
要查找从点到弧的距离:
- 首先,找到圆弧所隐含的椭圆的中心
- 使用atan2查找到该点的角度
- 使用cos(angle)* r1,sin(angle)* r2查找椭圆形的x,y截距
- 使用从x,y截距到点的距离公式
您可以在这里将弧度转换为度:
double polarDegrees = toDegrees(Math.atan2(y,x));
但是接下来的计算需要弧度。
所以只需删除toDegrees