using Masuit.Tools.Maths; using System; namespace Masuit.Tools.Models { /// /// 圆形 /// public class Circle { /// /// 圆形 /// /// 圆心坐标 /// 半径 public Circle(Point2D center, double radius) { Center = center; Radius = radius; if (radius < 0) { throw new ArgumentException("半径不能为负数", nameof(radius)); } } /// /// 圆心坐标 /// public Point2D Center { get; } /// /// 半径 /// public double Radius { get; } /// /// 是否相交 /// /// /// public bool IsCrossWith(Circle that) { var dis = Math.Sqrt(Math.Pow(that.Center.X - Center.X, 2) + Math.Pow(that.Center.Y - Center.Y, 2)); return that.Radius - Radius < dis && dis < that.Radius + Radius; } /// /// 是否相切 /// /// /// public bool IsIntersectWith(Circle that) { var dis = Math.Sqrt(Math.Pow(that.Center.X - Center.X, 2) + Math.Pow(that.Center.Y - Center.Y, 2)); return Math.Abs(that.Radius - Radius - dis) < 1e-7 || Math.Abs(dis - (that.Radius + Radius)) < 1e-7; } /// /// 是否相离 /// /// /// public bool IsSeparateWith(Circle that) { return !IsCrossWith(that) && !IsIntersectWith(that); } } }