如何检查线段与从水平角度的点发出的线光线之间的交点? [英] How do you check for intersection between a line segment and a line ray emanating from a point at an angle from horizontal?

查看:96
本文介绍了如何检查线段与从水平角度的点发出的线光线之间的交点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个线段,即两个点(x1,y1)和(x2,y2),一个点P(x,y)和一个角度θ。我们如何找到这条线段与从水平角度θ发出的线光线是否相交?如果他们确实相交,如何找到交点?

我们来标记点 q = x1 q EM> Y2 )。因此, s =( x2 - x1 y2 - y1 )。然后问题如下所示:



p>

r =(cosθ,sinθ)。那么通过 p 的射线上的任何点都可表示为 p + t r t ),并且线段上的任何点都可以表示为 q + u s u ≤1)。



如果我们可以找到 t u p + t r = q + u



p>

请参阅此答案以了解如何找到此点(或确定如果0≤t且0≤u≤1,则线段与射线相交。


Given a line segment, that is two points (x1,y1) and (x2,y2), one point P(x,y) and an angle theta. How do we find if this line segment and the line ray that emanates from P at an angle theta from horizontal intersects or not? If they do intersect, how to find the point of intersection?

解决方案

Let's label the points q = (x1, y1) and q + s = (x2, y2). Hence s = (x2x1, y2y1). Then the problem looks like this:

Let r = (cos θ, sin θ). Then any point on the ray through p is representable as p + t r (for a scalar parameter 0 ≤ t) and any point on the line segment is representable as q + u s (for a scalar parameter 0 ≤ u ≤ 1).

The two lines intersect if we can find t and u such that p + t r = q + u s:

See this answer for how to find this point (or determine that there is no such point).

Then your line segment intersects the ray if 0 ≤ t and 0 ≤ u ≤ 1.

这篇关于如何检查线段与从水平角度的点发出的线光线之间的交点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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