检查 android.graphics.path 与其自身的交集

发布于 2024-12-02 22:28:06 字数 210 浏览 0 评论 0原文

我想检查路径是否与自身相交(如果是,则碰撞在(x,y) - 只是为了突出显示)。 我如何检查一条路径是否与另一条路径相交也非常有趣。 这是一个屏幕截图,可以更好地解释我的意思:

https://i.sstatic.net/JrEmN.png< /a>

I'd like to check if (and if yes, where the collission is(x,y) - just for highlighting) a path does intersect itself.
It would also be very interesting how i do check if a path does intersect with another path.
Here is a screenshot to better explain what i mean:

https://i.sstatic.net/JrEmN.png

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挥剑断情 2024-12-09 22:28:06

最简单的方法是检查任何线段是否与任何其他线段相交。线段由路径中的成对相邻点组成。具有 10 个点的路径有 9 条线段。

下面是一个如何实现这一点的示例。

import android.graphics.Point;
import java.util.List;

static Boolean isPathComplex(List<Point> path) {

    if (path == null || path.size() <= 2) {
        return false;
    }

    int len = path.size();  

   for (int i = 1; i < len; i++) {
        Point lineAStart = path.get(i - 1);
        Point lineAEnd = path.get(i);

        for (int j = i + 1; j < len; j++) {
            Point lineBStart = path.get(j - 1);
            Point lineBEnd = path.get(j);
            if (lineSegmentsIntersect(lineAStart, lineAEnd, lineBStart, lineBEnd)) {
                return true;
            }

        } // inner loop

   } // outer loop

}

static Boolean lineSegmentsIntersect(Point aInitial, Point aFinal, Point bInitial, Point bFinal) {
    // left as an exercise to the reader
}

请参阅如何检测两条线段相交的位置? 有关如何实现 lineSegmentsIntersect 函数的示例。

The simplest way is to check if any line segment intersects with any other line segment. A line segment is made up of pairs of adjacent points in the path. A path with 10 points has 9 line segments.

Here's an example of how one might go about that.

import android.graphics.Point;
import java.util.List;

static Boolean isPathComplex(List<Point> path) {

    if (path == null || path.size() <= 2) {
        return false;
    }

    int len = path.size();  

   for (int i = 1; i < len; i++) {
        Point lineAStart = path.get(i - 1);
        Point lineAEnd = path.get(i);

        for (int j = i + 1; j < len; j++) {
            Point lineBStart = path.get(j - 1);
            Point lineBEnd = path.get(j);
            if (lineSegmentsIntersect(lineAStart, lineAEnd, lineBStart, lineBEnd)) {
                return true;
            }

        } // inner loop

   } // outer loop

}

static Boolean lineSegmentsIntersect(Point aInitial, Point aFinal, Point bInitial, Point bFinal) {
    // left as an exercise to the reader
}

See How do you detect where two line segments intersect? for an example of how to implement the lineSegmentsIntersect function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文