简体   繁体   English

如何使用 Mapbox(Turf) 找到圆和线(2 点)之间的交点

[英]How to find intersection point between circle and line(2 points) using Mapbox(Turf)

I'm finding how to find intersection point between circle and line(2 points) using Mapbox(Turf).我正在寻找如何使用 Mapbox(Turf) 找到圆和线(2 点)之间的交点。

Turfjs provides "intersect" function but Turf in java doesn't provide that function. Turfjs 提供“相交”function,但 java 中的 Turf 不提供 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:所以这是你如何做的:

  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.已经有一段时间了,你应该检查我是否以正确的方式调用 atan2,cosine 应该应用于 x 参数,sin 应用于 y 参数 - 三角学在学校教授的方式,角度 go 与我们的想法相反他们在指南针上,所以这里有些混乱。 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 https://sourceforge.net/p/tus/code/HEAD/tree/tjacobs/MathUtils.java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM