如何检查直线和矩形之间的交点?
问题描述:
标题说明了一切,我一直在搜寻,找不到任何直截了当的内容.我要如何用点(x1,y1)& (x2,y2)并检查其在矩形(xR,yR)之间的交点?我在Line2D包中看到了一些交集方法,但不确定如何设置所有交集方法.有人可以告诉我一种正确的设置方式来检查交叉点(碰撞)吗?
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 check its intersection between a rectangle (xR,yR)? I saw in the Line2D package that there were some intersection methods but not sure how to set it all up. Can someone show me a correct way of setting it up to check for an intersection (collision)?
答
使用2D图形API中的可用类.
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...