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.
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