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

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

问题描述

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

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?

推荐答案

让我们标记点 q = (x1, y1) 和q + s = (x2, y2).因此 s = (x2x1, y2y1).那么问题看起来是这样的:

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

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

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).

如果我们能找到 tu 使得 p + t r = q + u s:

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).

如果 0 ≤ t 且 0 ≤ u ≤ 1,则您的线段与射线相交.

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

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

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