簡體   English   中英

如何使用 Mapbox(Turf) 找到圓和線(2 點)之間的交點

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

我正在尋找如何使用 Mapbox(Turf) 找到圓和線(2 點)之間的交點。

Turfjs 提供“相交”function,但 java 中的 Turf 不提供 function。

我想知道如何計算交點(經度和緯度)。

我的代碼如下:

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. 求角度:角度(以弧度為單位)是

     double xdiff = x1 - x2; double ydiff = y1 - y2; //double tan = xdiff / ydiff; double atan = Math.atan2(ydiff, xdiff); return atan;
  2. 現在你可以找到圓上的點,通過

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

已經有一段時間了,你應該檢查我是否以正確的方式調用 atan2,cosine 應該應用於 x 參數,sin 應用於 y 參數 - 三角學在學校教授的方式,角度 go 與我們的想法相反他們在指南針上,所以這里有些混亂。 但這應該讓您了解如何解決這個問題。

有關更多信息,您可以檢查

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