1

I'm finding how to find intersection point between circle and line(2 points) using Mapbox(Turf).

Turfjs provides "intersect" function but Turf in java doesn't provide that function.

I wonder how to calculate intersection point(longitude and latitude).

My code below:

public void circleIntersectionPointTest() {
        Point circleCenter = Point.fromLngLat(1.0, 1.0);
        double circleRadius = 35; //nautical mile
        Polygon circle = TurfTransformation.circle(circleCenter, circleRadius, TurfConstants.UNIT_NAUTICAL_MILES);

        Point innerPoint = Point.fromLngLat(1.0, 0.5);
        Point outerPoint = Point.fromLngLat(2.0, 1.5);

        //how to find between circle and line with innerPoint and outerPoint
        Point intersectionPoint;
    }

1 Answer 1

0

So here's how you do it:

  1. Find the angle: The angle (in radians) is

     double xdiff = x1 - x2;
     double ydiff = y1 - y2;
     //double tan = xdiff / ydiff;
     double atan = Math.atan2(ydiff, xdiff);
     return atan;
    
  2. Now you can find the point on the circle, via

    circleCenter.x + sin(angle) * circleRadius, circleCenter.y + cos(angle) * circleRadius 
    

It's been a while and you should check that I am invoking atan2 the right way, and cosine should be applied to the x parameter and sin to the y parameter - the way trigonometry is taught in school, angles go the opposite way as how we think of them on a compass, so there's some confusion here. But this should give you the idea of how to solve this.

For more, you can check

https://sourceforge.net/p/tus/code/HEAD/tree/tjacobs/MathUtils.java

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.