I want to detect a line intersection using Android.graphics.Path
. Right now, it seems that the intersection is always empty, even though the lines should intersect. To reproduce this, I created this simplifed code that is running within my Activity's onCreate()
Method:
Path leftToRight = new Path();
leftToRight.moveTo(0,0);
leftToRight.lineTo(200,200);
Path rightToLeft = new Path();
rightToLeft.moveTo(200,0);
rightToLeft.lineTo(0,200);
Path resultPath = new Path();
if (resultPath.op(rightToLeft, leftToRight, Path.Op.INTERSECT)) {
if (!resultPath.isEmpty()) {
Log.d(this.getLocalClassName(), "INTERSECTION DETECTED");
} else {
Log.d(this.getLocalClassName(), "NO INTERSECTION DETECTED");
}
}
The log output says 'NO INTERSECTION DETECTED'. I already read many answers around this topic on StackOverflow, like here, but using Region.op is not an option in my case, as my tests showed that it will create a rectangle around the path before intersecting.
Some sources indicate that intersect might only properly work for Path objects that have a closed bound, like a square or a rectangle. But I can hardly imagine that Google would not implement basic line intersection. What am I missing here?
So I am thankful for a plain answer, whether it is possible to intersect Paths that just contain lines in Android using this method, or not.