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;
}
So here's how you do it:
Find the angle: The angle (in radians) is
Now you can find the point on the circle, via
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