这应该找到任何任意多边形的所有相交段。
将多边形视为边 AB、BC、CD 等的有序集合,其中从每条边的第一个点到其第二个点的“方向”是“顺时针”。也就是说,如果我们正在查看点 A,那么当顺时针移动时,点 B 就是下一个点。
方法是找到穿过平面的多边形的边,然后找到下一条线段,顺时针移动,回到平面的原始边。这些线段与平面相交的两个点形成相交线段的端点。重复此操作,直到检查完所有多边形的边缘。
请注意,如果多边形是凹的,则并非所有线段都必须在多边形内。
let P be any point on the polygon.
TOP:
while (P has not been checked)
mark P as having been checked.
let f be the point following P, clockwise.
if (P and f are on opposite sides of the plane) then
Continuing from f clockwise, find the next point Y that is on
the same side of the plane as P.
Let z be the point counter-clockwise from Y.
(note - Sometimes z and f are the same point.)
let S1 be the point where P,f intersects the plane
let S2 be the point where Y,z intersects the plane
if (segment (S1,S2) is inside the polygon)
add (S1,S2) to a 'valid' list.
let P = Y
else
let P = f
endif
else
let P = f
endif
endwhile
该算法物有所值。:-)