线相交
如何判断一条线是否被多边形截断
How to find whether a line intercepted in a polygon
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何判断一条线是否被多边形截断
How to find whether a line intercepted in a polygon
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
根据您到底想要什么(我将假设一个线段,因为我本周刚刚编写了该代码),您可以将其分为两部分:
首先,我建议对行进行编码,
因为该形式没有行的极端情况例如
X=5
、Y=4
或X=3*Y
。Depending on what exactly you want (I'll assume a line segment as I just wrote that code this week) you can get it in two parts:
first of all I'd suggest encoding lines as
because that form has no corner cases for lines like
X=5
,Y=4
orX=3*Y
.这个问题有点含糊,但我们还是尝试一下:
假设直线上的点 (x,y) 由方程 Ax + By + C = 0 定义。
那么我们显然可以通过评估来确定点 (x,y) 是否在线上
Ax + By + C。如果该点不在直线上,则 Ax + By + C 的符号告诉我们该点位于直线的哪一侧。
因此,通过检查多边形每个顶点 (x,y) 的表达式 Ax + By + C 的符号,我们可以确定多边形的所有点是否在线的同一侧。
(一个稍微不同的问题是确定多边形是否与线段相交。)
The question is a little bit ambiguous but let's try anyway:
Assume the points (x,y) on the line are defined by the equation Ax + By + C = 0.
Then we can obviously determine if a point (x,y) is on the line by evaluating
Ax + By + C. If the point is not on the line then the sign of Ax + By + C tells us on which side of the line the point is.
Hence by inspecting the signs of the expression Ax + By + C for each vertex (x,y) of the polygon, we can determine if all points of the polygon are on the same side of line or not.
(A slightly different problem would be to determine if a polygon intersects a line segment.)
中找到的此实现中阅读合理的答案
您可以从某些网页参考
。
C++ 示例:几何概念、线相交及其应用、2D 绘图
通过 lbackstrom
来自 ucancode 网站
You can read a reasonable answer from this implementation found in some webpage
}
Reference.
C++ Example: Geometry Concepts Line Intersection and its Applications, 2D drawing
By lbackstrom
from site ucancode
您需要坐标图上多边形的点以及直线的斜率以及 x 和 y 截距来查找该信息。 从那里开始就是简单的数学计算。
You need the points of the polygon on a coordinate graph and the slope and x and y intercept of the line to find that information. From there it's simple math.