如何检查线段与从水平角度的点发出的线光线之间的交点? [英] How do you check for intersection between a line segment and a line ray emanating from a point at an angle from horizontal?
问题描述
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 = (x2 − x1, y2 − y1). 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屋!