Crossing the path in android

I have 2 path objects in my Android code. I tried all the paths to check if these paths intersect or not, but I am not able to do this. How can I check if paths intersect or not. I appreciate any good answer, thanks!

+5
source share
3 answers

look Region.op

I have not tried, but I would suggest using:

Region.setPath(Path path, Region clip);

to get an area from both of your paths, and then you can use:

if (region1.op(region2,Region.Op.INTERSECT)) {
  // intersection
}

to check the intersection ...

+4
source

The answer received by Dheeraj has the answer to your question:

fooobar.com/questions/1117791 / ...

Here is a copy and paste of his answer:

, , , .

, , :

Path path1 = new Path();
path1.addCircle(10, 10, 4, Path.Direction.CW);
Path path2 = new Path();
path2.addCircle(15, 15, 8, Path.Direction.CW);

Region region1 = new Region();
region1.setPath(path1, clip);
Region region2 = new Region();
region2.setPath(path2, clip);

if (!region1.quickReject(region2) && region1.op(region2, Region.Op.INTERSECT)) {
    // Collision!
}

, drawPath(). () .

, "clip" .

Region clip = new Region(0, 0, layoutWidth, layoutHeight);

- .

+7

API 19, Path op() .

boolean intersects = path.op(p1,p2,Path.Op.INTERSECT)
+6

All Articles