1
當試圖計算兩個凸多邊形的Minkowski差異時,我可以簡單地找到頂點集並使用禮物包裝算法來查找凸包。 (見下文)Minkowski與凹多邊形的差異
但是對於凹多邊形來說,凸包算法並不合適,因爲它會給我一個碰撞誤報,有沒有一種方法可以使我的代碼很容易地找到正確的擴展產生的?
public List<Vector2D> MinkowskiDifference(Polygon other)
{
List<Vector2D> vList = new List<Vector2D>();
foreach (Vector2D vT in this.vertices)
{
foreach (Vector2D vO in other.vertices)
{
vList.Add((vT+this.position) - (vO+other.position));
}
}
return vList;
}
public static Polygon ConvexHull(List<Vector2D> vList)
{
List<Vector2D> S = vList;
List<Vector2D> P = new List<Vector2D>();
Vector2D endpoint;
Vector2D pointOnHull = LeftMostPoint(S);
int i = 0;
do
{
P.Add(pointOnHull);
endpoint = S[0];
for (int j = 1; j < S.Count; j++)
{
if (endpoint == pointOnHull || RelPosition(P[i], endpoint, S[j]) == -1)
{
endpoint = S[j];
}
}
i++;
pointOnHull = endpoint;
} while (endpoint != P[0]);
return new Polygon(P);
}
感謝您的答覆,顯然這是一件我會需要做的還多讀成。 –