我被这个小问题卡住了,我的解决算法对于所有情况都不适用。有人有什么想法如何解决吗?
这里是一个多边形的示例:
示例 http://img148.imageshack.us/img148/8804/poly.png
形式化描述:
我们有一个由顺时针方向定义的点列表来定义此多边形。我们还可以查询一个点是否是切点,使用 is_cut(p)
,其中p
是给定的点。现在,我们要计算由这个“切割”引起的新多边形。
该算法应该执行以下操作:
输入:{a, c1, b, c4, c, c5, d, c6, e, c3, f, c2}
输出:{a, c1, c2}
,{b, c4, c3, f, c2, c1}
,{d, c6, c5}
,{e, c3, c4, c, c5, c6}
这是我的当前算法:
follow your points, CW
if the point is a cut point
-> go back trough the list looking for cut points
--- if next cut point is connected to the current cut point
and not part of the current poly, follow it
--- else keep searching
else
-> continue until you hit your starting point.
that's a poly
do this for every non-cut-point
如果你从c
或者f
开始,这个算法就不适用了。