這應該找到所有的相交的部分,對於任意多邊形。
將多邊形看作邊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
這個算法很值得你爲它付出。 :-)
對於交叉多邊形的每個線段並連接點有點微不足道的事情,你有什麼反對嗎? – 2010-10-17 01:44:22
這就是我想象的解決方案。 Java3D能否與一個多邊形相交的線段並返回交點?我必須小心非凸多邊形相交兩次,但我認爲我可以處理,如果我只能得到交點... – 2010-10-17 01:53:47
我不知道Java3D,快速搜索顯示這個:http: //code.j3d.org/using/geom_intersect.html – 2010-10-17 04:22:48