static bool PolygonCollision(PolygonForCollision polygonA, PolygonForCollision polygonB) { bool Intersect = true; int edgeCountA = polygonA.Edges.Count; int edgeCountB = polygonB.Edges.Count; VectorForCollision edge; for (int edgeIndex = 0; edgeIndex < edgeCountA + edgeCountB; edgeIndex++) { if (edgeIndex < edgeCountA) { edge = polygonA.Edges[edgeIndex]; } else { edge = polygonB.Edges[edgeIndex - edgeCountA]; } VectorForCollision axis = new VectorForCollision(-edge.Y, edge.X); axis.Normalize(); float minA = 0; float minB = 0; float maxA = 0; float maxB = 0; ProjectPolygon(axis, polygonA, ref minA, ref maxA); ProjectPolygon(axis, polygonB, ref minB, ref maxB); if (IntervalDistance(minA, maxA, minB, maxB) > 0) { Intersect = false; } } return(Intersect); }
public void Offset(float x, float y) { for (int i = 0; i < points.Count; i++) { VectorForCollision p = points[i]; points[i] = new VectorForCollision(p.X + x, p.Y + y); } }
static void ProjectPolygon(VectorForCollision axis, PolygonForCollision polygon, ref float min, ref float max) { float d = axis.DotProduct(polygon.Points[0]); min = d; max = d; for (int i = 0; i < polygon.Points.Count; i++) { d = polygon.Points[i].DotProduct(axis); if (d < min) { min = d; } else { if (d > max) { max = d; } } } }
public bool Equals(VectorForCollision v) { return(X == v.X && Y == v.Y); }
public override bool Equals(object obj) { VectorForCollision v = (VectorForCollision)obj; return(X == v.X && Y == v.Y); }
public float DistanceTo(VectorForCollision vector) { return((float)Math.Sqrt(Math.Pow(vector.X - this.X, 2) + Math.Pow(vector.Y - this.Y, 2))); }
public float DotProduct(VectorForCollision vector) { return(this.X * vector.X + this.Y * vector.Y); }
static public VectorForCollision FromPoint(Point p) => VectorForCollision.FromPoint(p.X, p.Y);
public void Offset(VectorForCollision v) { Offset(v.X, v.Y); }