When trying to calculate the Minkowski difference of two convex polygons I can simply find the set of vertices and use a gift wrapping algorithm to find the convex hull. (see below.)
However for concave polygons the convex hull algorithm is not appropriate as it will give me a false positive on collisions, is there a way I can adapt my code to easily find the correct expansion using the points already generated?
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);
}
