0
votes

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 
2
Your question is for distance from a point to an arc, but the function you've posted is for a point to a lineControlAltDel
sorry about the name. The method is for point to arc distance. Ive updated the name as well now.user101

2 Answers

0
votes

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
0
votes

You transform radians to degrees here:

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

but the next calculations need radians.

So just remove toDegrees