确定无限线和线段是否相交的公式? [英] Formula to determine if an infinite line and a line segment intersect?

查看:88
本文介绍了确定无限线和线段是否相交的公式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一条线上的点,该线的斜率将如何确定在每个方向上无限延伸的该线是否与线段(x1,y1)(x2,y2)相交,如果相交,则该相交点发生了吗?

Given a point on a line and that line's slope how would one determine if the line, extending in each direction infinitely, intersects with a line segment (x1,y1), (x2,y2) and, if so, the point at which the intersection occurs?

我找到了这个,但不确定在这里是否有帮助.
如果有人想帮助我理解光线",那对我来说没关系. http://www.realtimerendering.com/intersections.html

I found this, but I'm unsure if it's helpful here.
If someone wants to help me understand "rays", that's alright with me. http://www.realtimerendering.com/intersections.html

对不起,我是个白痴.

I'm sorry that I'm an idiot.

推荐答案

第一行的任意点具有参数方程式

Arbitrary point on the first line has parametric equation

dx = Cos(slope)
dy = Sin(Slope)
x = x0 + t * dx     (1)
y = y0 + t * dy

包含第二段的行

dxx = x2 - x1
dyy = y2 - y1
x = x1 + u * dxx    (2)
y = y1 + u * dyy

如果存在线性系统,则存在交点

Intersection exists if linear system

x0 + t * dx = x1 + u * dxx   (3)    
y0 + t * dy = y1 + u * dyy

具有未知数tu
的解决方案 并且u位于范围[0..1]

has solution for unknowns t and u
and u lies in range [0..1]

可以用等式对(2)中的u代替来计算交叉点

Intersection point could be calculated with substitution of u found in the equation pair (2)

这篇关于确定无限线和线段是否相交的公式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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