由网友(自春生 入秋藏)分享简介:我有两个凸多边形。多边形被实现为它们的顶点的环状列表。如何找到这两个多边形的交集?解决方案 对于第一个多边形的每个边V1,V2,令H:=半平面tangenting V1-V2时,与剩余的在内部的顶点。令C:=新空的多边形。为在第2多边形的每个边V3-V4,令X:= V3,V4和H之间的交集如果V3的内部H和V 4是...![与凸多边形对角线相关的几个问题](https://p.xsw88.cn/allimgs/daicuo/20230911/2834.png)
我有两个凸多边形。多边形被实现为它们的顶点的环状列表。如何找到这两个多边形的交集?
解决方案 对于第一个多边形的每个边V1,V2,
令H:=半平面tangenting V1-V2时,与剩余的
在内部的顶点。
令C:=新空的多边形。
为在第2多边形的每个边V3-V4,
令X:= V3,V4和H之间的交集
如果V3的内部H和V 4是H以外的话,
添加V3为C.
增加X C.
否则,如果两个V3和V4在于ħ外然后,
跳跃。
否则,如果V3ħ外,和V4是里面H,则,
增加X C.
其他
添加V3为C.
更换第二个多边形C.
这应该足够简单的使用; :10-20顶点和不重新计算每一帧。 — O( N 的 2 )
下面是几个链接:
图形学I&ndash的;多边形裁剪和灌装(PDF) 罗塞塔code.org&ndash的;萨瑟兰-Hodgman多边形裁剪![与凸多边形对角线相关的几个问题](https://p.xsw88.cn/allimgs/daicuo/20230911/2834.png)
I have two convex polygons. Polygons are implemented as cyclic lists of their vertices. How to find an intersection of this two polygons?
解决方案For each edge V1-V2 in the first polygon,
Let H := Half-plane tangenting V1-V2, with the remaining
vertices on the "inside".
Let C := New empty polygon.
For each edge V3-V4 in the second polygon,
Let X := The intersection between V3-V4 and H.
If V3 inside H, and V4 is outside H then,
Add V3 to C.
Add X to C.
Else if both V3 and V4 lies outside H then,
Skip.
Else if V3 outside H, and V4 is inside H then,
Add X to C.
Else
Add V3 to C.
Replace the second polygon with C.
This should suffice for simple usage; 10-20 vertices and not recalculating every frame. — O(n2)
Here is a few links:
Computer Graphics I – Polygon Clipping and Filling (pdf) rosettacode.org – Sutherland-Hodgman polygon clipping相关推荐
最新文章