/// <summary> /// Checks if a Point lies in a circle /// (This is a strictly static method for performance reasons) /// </summary> /// <param name="middlePoint"></param> /// <param name="radius"></param> /// <param name="checkPoint"></param> /// <param name="tolerance"></param> /// <returns></returns> public static bool Contains(Vector2 middlePoint, double radius, Vector2 checkPoint, double tolerance) { var len = LineSegment2.CalcLenght(middlePoint, checkPoint); var dist = radius - (len - tolerance); return(dist >= 0); }
private bool InterceptWithCircle(Circle2 other, double tolerance = GeometrySettings.DEFAULT_TOLERANCE) { var middlepointDistance = LineSegment2.CalcLenght(this.MiddlePoint, other.MiddlePoint); var radiusSum = this.Radius + other.Radius; return(!(middlepointDistance > (radiusSum + tolerance))); }
/// <summary> /// Does a Point lie on the Arc line? /// </summary> /// <param name="point"></param> /// <param name="tolerance"></param> /// <returns></returns> public bool Contains(Vector2 point, double tolerance = GeometrySettings.DEFAULT_TOLERANCE) { bool conatins = false; // First, the distance from middlepoint to our Point must be equal to the radius: var distance = LineSegment2.CalcLenght(this.MiddlePoint, point); if (Math.Abs(distance - this.Radius) < tolerance) { // If this is true, we only need to check if we are in the arc angle var bowMiddle = this.GetPointOnArc(this.Angle / 2); var l1 = new LineSegment2(this.Location, bowMiddle); var l2 = new LineSegment2(this.GetPointOnArc(this.Angle), bowMiddle); var intersection = new LineSegment2(this.MiddlePoint, point); conatins = intersection.IntersectLine(l1, tolerance).HasValue || intersection.IntersectLine(l2, tolerance).HasValue; } return(conatins); }
private IEnumerable <Vector2> InterceptCircle(Circle2 other, double tolerance = GeometrySettings.DEFAULT_TOLERANCE) { var interceptions = new List <Vector2>(); if (InterceptWithCircle(other, tolerance)) { var middlepointDistance = LineSegment2.CalcLenght(this.MiddlePoint, other.MiddlePoint); if (middlepointDistance < Math.Abs(this.Radius + other.Radius)) { // circle is contained in other } else if (middlepointDistance == 0 && (this.Radius == other.Radius)) { // circle are concident -> infinite numbers of intersections } else { interceptions.AddRange(IntersectCircle(this, other)); } } return(interceptions); }