如何检查直线和矩形之间的交点? [英] How to check intersection between a line and a rectangle?

查看:300
本文介绍了如何检查直线和矩形之间的交点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题说明了一切,我一直在搜寻,找不到任何直截了当的内容.我要如何用点(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...

这篇关于如何检查直线和矩形之间的交点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆