2010-08-16 18 views
1

我怎樣才能實現這個方法:查找列表<Point>是否代表一個規則或不規則的多邊形

private bool IsRegularPolygon(List<Point> seed)

Point對象是在2個維度,用X和Y座標。

並假設它是規則的,我怎麼能找到一邊的長度?

謝謝!

+0

平均得到假設中心的座標,轉換爲極座標,然後檢查向中心的矢量是否具有相同的長度,並且對於每個假設的頂點具有等距角度:-) – 2010-08-16 11:54:52

回答

0

回想一下高中幾何學,並考慮是什麼讓一個多邊形「常規」。

因爲如果這就是我所說的話,那麼我就要去追逐它,並指出它是一個多邊形,所有內角都相等。

因此,這可以將問題降低到確保列表中三個點之間的每個角度都相同。因此,像:

get the first point, and the two after it 
find the angle between them, store it somewhere 
get the second point, and the two after it 
find the angle between them, make sure it's the same 
repeat the last two steps for all the points in the list 

現在記住的是,如果它是定期的,所有的邊的長度相同,所以找到邊長是一個簡單的距離之間二點計算。