0

I just create two paths of straight lines which intersect, I use Path.combine to know if they intersect or not and it is always false, and I don't understand why, I would like to know what is wrong or if there is another way to know if two lines intersect or not:

final path = Path();
path.moveTo(100, 300);
path.lineTo(300, 300);

final path2 = Path();
path2.moveTo(200, 200);
path2.lineTo(200, 400);

canvas.drawPath(path, _pencilPaint);
canvas.drawPath(path2, _pencilPaintGreen);

final intersection = Path.combine(
  PathOperation.intersect,
  path,
  path2,
);
final pathsAreIntersecting = !(intersection.getBounds().isEmpty);

print(pathsAreIntersecting); // ALWAYS FALSE

enter image description here

Daniel Roldán
  • 1,328
  • 3
  • 20
  • 1
    it's a [math](https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection) problem, `Path.combine` cannot be used as an intersection of two lines results in a single point which has no size – pskink Sep 23 '22 at 07:20
  • Ok ok, and is there any way to know when two lines intersect ? – Daniel Roldán Sep 23 '22 at 07:32
  • 1
    this one is better in your case https://en.wikipedia.org/wiki/Intersection_(geometry)#Two_line_segments – pskink Sep 23 '22 at 07:35

0 Answers0