public static List <Intersection> CheckIntersection(Sphere sphere, PlaneCollider plane) { var intersections = new List <Intersection> (); double dist = Vec3.Dot(sphere.x, plane.normal) - plane.d; double d = Math.Abs(dist) - sphere.r; if (d < 0) { var p = sphere.x - (Vec3.Dot(plane.normal, sphere.x) + plane.d) * plane.normal; intersections.Add(new Intersection { entity = plane.self, distance = -d, normal = plane.normal, point = p }); } return(intersections); }
public static List <Intersection> CheckIntersection(IEnumerable <Particle> ps, PlaneCollider pl) { List <Intersection> intersections = new List <Intersection> (); foreach (var p in ps) { double d = Math.Abs(Vec3.Dot(p.x, pl.normal) - pl.d); if (d < PlaneCollider.thickness) { Intersection data = new Intersection { entity = p, distance = PlaneCollider.thickness - d, normal = pl.normal, point = (p.x - (Vec3.Dot(pl.normal, p.x) + pl.d) * pl.normal) + PlaneCollider.thickness * pl.normal }; intersections.Add(data); } } return(intersections); }