/// <summary> /// Indicates whether any portion of this sphere and the <paramref name="other"/> shape overlap. /// </summary> /// <param name="other">The shape to check against this one.</param> /// <returns>True if any part of both shapes overlap, false if they are entirely separate.</returns> public bool Intersects(Cylinder other) { float errorMargin = MathUtils.FlopsErrorMargin; float cylinderHalfHeight = other.Height / 2f; if (other.Center.Y + cylinderHalfHeight < Center.Y - Radius + errorMargin || other.Center.Y - cylinderHalfHeight > Center.Y + Radius + errorMargin) { return(false); } float distanceToCylinderTop = Math.Abs((other.Center.Y + cylinderHalfHeight) - Center.Y); float distanceToCylinderBottom = Math.Abs((other.Center.Y - cylinderHalfHeight) - Center.Y); float sphereRadiusAtCylinderTop = distanceToCylinderTop > Radius ? 0f : GetRadius(distanceToCylinderTop); float sphereRadiusAtCylinderBottom = distanceToCylinderBottom > Radius ? 0f : GetRadius(distanceToCylinderBottom); return(Vector3.Distance(Center[0, 2], other.Center[0, 2]) - Math.Max(sphereRadiusAtCylinderTop, sphereRadiusAtCylinderBottom) <= other.Radius + errorMargin); }
/// <summary> /// Indicates whether or not the given shape is contained entirely within this sphere (no part of the <paramref name="other"/> /// shape may be outside this one). /// </summary> /// <param name="other">The shape to check.</param> /// <returns>True if the other shape is completely within this sphere, false if any part of it /// is outside the sphere.</returns> public bool Contains(Cylinder other) { return(Contains(other.ToSymmetricalConicalFrustum())); }
/// <summary> /// Indicates whether any portion of this cone and the <paramref name="other"/> shape overlap. /// </summary> /// <param name="other">The shape to check against this one.</param> /// <returns>True if any part of both shapes overlap, false if they are entirely separate.</returns> public bool Intersects(Cylinder other) { return(other.ToSymmetricalConicalFrustum().Intersects(this)); }