///<summary>
/// Represents a 2D circle. 表示一个2D圆形 /// </summary> struct Circle { /// <summary> /// Center position of the circle. 圆心 /// </summary> public Vector2 Center; /// <summary> /// Radius of the circle. 半径 /// </summary> public float Radius; /// <summary> /// Constructs a new circle. 创建一个圆形 /// </summary> public Circle(Vector2 position, float radius) { Center = position; Radius = radius; } /// <summary> /// Determines if a circle intersects a rectangle. 判断圆是否与矩形相交 /// </summary> /// <returns>True if the circle and rectangle overlap. False otherwise.</returns> public bool Intersects(Rectangle rectangle) { Vector2 v = new Vector2(MathHelper.Clamp(Center.X, rectangle.Left, rectangle.Right), MathHelper.Clamp(Center.Y, rectangle.Top, rectangle.Bottom)); Vector2 direction = Center - v; float distanceSquared = direction.LengthSquared(); return ((distanceSquared > 0) && (distanceSquared < Radius * Radius)); } }
浙公网安备 33010602011771号