這裏有一個簡單的算法:
for each line segment in the chain:
Identify any segments which cross this segment
If crossings > 0
Follow the branch to the right, if this doesn't lead back to the
current intersection follow the branch to the left
go to the next line segment
如果下面的一個分支不會導致回那個路口前往,這意味着你跳過一個循環鏈的末端之前,所以你需要選擇其他分支。
對於你的榜樣,運行該算法將產生
Start at segment A1-A2
No intersections, goto next
Segment A2-A3
Intersection A2-A3/A6-A5 choose right path and store the current intersection somewhere
Segment A6-A5
Intersection A6-A5/A4-A3 choose right path and store intersection
Segment A3-A4
A4-A5
A5-A6
Back at intersection A6-A5/A4-A3, go right again to be back on A4-A3
A3-A2
Back at intersection A2-A3/A6-A5, go right again
Finish
你的問題不是很清楚。你能提供一個你期望輸出的數字嗎?同樣,_same shape_的意思是什麼?形狀似乎沒有很好的路徑定義... – 2010-06-04 04:35:02
@Moron,但我列出*精確*輸出我正在尋找 - 我鏈接到的圖像給出了我列出的上下文的輸出。 – 2010-06-04 04:56:25
感謝編輯Nick!我應該知道我可以嵌入圖像。 – 2010-06-04 04:57:59