public float Distance(Sphere other) => (Center.Distance(other.Center) - Radius - other.Radius).ClampLower(0);
public ContainmentType Contains(Sphere sphere) { if (sphere.Center.X - Min.X >= sphere.Radius && sphere.Center.Y - Min.Y >= sphere.Radius && sphere.Center.Z - Min.Z >= sphere.Radius && Max.X - sphere.Center.X >= sphere.Radius && Max.Y - sphere.Center.Y >= sphere.Radius && Max.Z - sphere.Center.Z >= sphere.Radius) { return(ContainmentType.Contains); } double dmin = 0; double e = sphere.Center.X - Min.X; if (e < 0) { if (e < -sphere.Radius) { return(ContainmentType.Disjoint); } dmin += e * e; } else { e = sphere.Center.X - Max.X; if (e > 0) { if (e > sphere.Radius) { return(ContainmentType.Disjoint); } dmin += e * e; } } e = sphere.Center.Y - Min.Y; if (e < 0) { if (e < -sphere.Radius) { return(ContainmentType.Disjoint); } dmin += e * e; } else { e = sphere.Center.Y - Max.Y; if (e > 0) { if (e > sphere.Radius) { return(ContainmentType.Disjoint); } dmin += e * e; } } e = sphere.Center.Z - Min.Z; if (e < 0) { if (e < -sphere.Radius) { return(ContainmentType.Disjoint); } dmin += e * e; } else { e = sphere.Center.Z - Max.Z; if (e > 0) { if (e > sphere.Radius) { return(ContainmentType.Disjoint); } dmin += e * e; } } if (dmin <= sphere.Radius * sphere.Radius) { return(ContainmentType.Intersects); } return(ContainmentType.Disjoint); }
/// <summary> /// Gets whether or not the other <see cref="Sphere"/> intersects with this sphere. /// </summary> public bool Intersects(Sphere sphere) { var sqDistance = sphere.Center.DistanceSquared(Center); return(!(sqDistance > (sphere.Radius + Radius) * (sphere.Radius + Radius))); }
public static Box CreateFromSphere(Sphere sphere) => new Box(sphere.Center - new Vector3(sphere.Radius), sphere.Center + new Vector3(sphere.Radius));