How to check intersection between a line and a rectangle?

前端 未结 3 1599
悲&欢浪女
悲&欢浪女 2020-12-17 19:20

The title says it all, Ive been searching around and couldnt find anything that was straight and to the point. How would I take a line with points (x1,y1) & (x2, y2) and

3条回答
  •  悲哀的现实
    2020-12-17 19:55

    Using the available classes from the 2D Graphics API.

    Rectangle r1 = new Rectangle(100, 100, 100, 100);
    Line2D l1 = new Line2D.Float(0, 200, 200, 0);
    System.out.println("l1.intsects(r1) = " + l1.intersects(r1));
    

    What this doesn't tell you, is where...

提交回复
热议问题