本文介绍了检查与自己的android.graphics.path交集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

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

解决方案

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



下面是一个例子,说明如何去做。

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

静态布尔值isPathComplex(List< Point>路径){

if(path == null || path.size()返回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 Point lineBStart = path.get(j - 1);
Point lineBEnd = path.get(j);
if(lineSegmentsIntersect(lineAStart,lineAEnd,lineBStart,lineBEnd)){
return true;
}

} //内循环

} //外循环

}

static Boolean lineSegmentsIntersect(Point aInitial,Point aFinal,Point bInitial,Point bFinal){
//作为练习留给读者
}

请参阅,以获取如何实现lineSegmentsIntersect函数的示例。


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:

http://i.stack.imgur.com/JrEmN.png

解决方案

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.

这篇关于检查与自己的android.graphics.path交集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 13:58