private static bool CircleHalfPlane(CircleCollider c, HalfPlaneCollider hp) { // Distance from the circle's center to the half-plane. float distance = Math.Abs(hp.A * (c.position.X + c.center.X) + hp.B * (c.position.Y + c.center.Y) + hp.C) / (float)Math.Sqrt(hp.A * hp.A + hp.B * hp.B); if (distance < c.Radius) { return(true); } return(false); }
private static bool PolygonHalfPlane(PolygonCollider p, HalfPlaneCollider hp) { // Just check if any of the polygon's vertices satisfies the half-plane's equation. foreach (Vector2 v in p.vertices) { if (hp.A * v.X + hp.B * v.Y <= hp.C) { return(true); } } // If none does, there is no intersection. return(false); }
private static bool HalfPlane(HalfPlaneCollider k, HalfPlaneCollider l) { if ((k.A * l.B) - (k.B * l.A) == 0) { // The two lines defining the half-planes are parallel. // The lines can't intersect, but the half-planes still might! // @todo I'm not sure about this, should make sure! if (k.C < l.C) { return(true); } return(false); } // The lines are intersecting, so the half-planes are, too. return(true); }
private static bool AABBHalfPlane(AABBCollider a, HalfPlaneCollider hp) { // Check if any of the AABB's vertices satisfies the half-plane's equation. if (hp.A * a.position.X + hp.B * a.position.Y <= hp.C) { return(true); } if (hp.A * a.position.X + hp.B * (a.position.Y + a.Height) <= hp.C) { return(true); } if (hp.A * (a.position.X + a.Width) + hp.B * a.position.Y <= hp.C) { return(true); } if (hp.A * (a.position.X + a.Width) + hp.B * (a.position.Y + a.Height) <= hp.C) { return(true); } return(false); }