/// <summary>Finds the intersection points between the edge of this circle and circle <paramref name='b'/>.</summary> /// <returns>Null (no intersection), an array of length 1, or an array of length 2.</returns> public WPoint[] GetIntersectionPoints(WCircle b) { //following the method in math/intersectionCircleCircle.png WCircle a = this; double d = a.Center.Distance(b.Center); //distance between centers if (d > a.Radius + b.Radius) { return(null); //circles too far apart to intersect } if (a.ContainsOrIsContained(b)) { return(null); //one circle is wholly inside the other } //the radical line is the line between the two intersecting points of the circles //Point c is the center of the radical line, which is also on the line between the centers double dA = (Math.Pow(a.Radius, 2) - Math.Pow(b.Radius, 2) + Math.Pow(d, 2)) / (2 * d); //distance from centerA to pointC if (dA == a.Radius) { return(new WPoint[] { Geometry.PointOnLine(a.Center, b.Center, a.Radius) }); //circles intersect at single point } WPoint c = a.Center + dA * (b.Center - a.Center) / d; //h is the distance from pointC to either intersection point (the hypotenus of triangle centerA-C-intersection) double h = Math.Sqrt(Math.Pow(a.Radius, 2) - Math.Pow(dA, 2)); return(new WPoint[] { new WPoint(c.X + (h * (b.Y - a.Y) / d), c.Y - h * (b.X - a.X) / d), new WPoint(c.X - (h * (b.Y - a.Y) / d), c.Y + h * (b.X - a.X) / d) }); }
/// <summary> /// Returns true if this circle entirely contains circle <paramref name='b'/>, or <paramref name='b'/> entirely contains this circle, or they exactly overlap. /// </summary> public bool ContainsOrIsContained(WCircle b) { if (this.Radius > b.Radius) { return(this.Contains(b)); } return(b.Contains(this)); }
/// <summary> /// Returns true if any part of this circle overlaps any part of circle <paramref name='b'/>. /// </summary> public bool Overlaps(WCircle b) { WPoint[] intersections = this.GetIntersectionPoints(b); if (intersections != null) { return(true); } return(this.ContainsOrIsContained(b)); }
/// <summary> /// Find the two tangent points on the circle that form lines to point <paramref name='b'/>. /// </summary> /// <returns>Array of length 2.</returns> public WPoint[] GetTangentPoints(WPoint b) { //point C and D are the tangents WCircle a = this; double distanceAB = a.Center.Distance(b); double degreesAB = DegreesAtPoint(b); double degreesAB_AC = Math.Cos(Radius / distanceAB); WPoint c = PointAtDegrees(degreesAB + degreesAB_AC); WPoint d = PointAtDegrees(degreesAB - degreesAB_AC); return(new WPoint[] { c, d }); }
/// <summary> /// Returns true if this wedge fully contains circle <paramref name='b'/>. /// </summary> public bool Contains(WCircle b) { WPoint[] tangentPoints = b.GetTangentPoints(this.Circle.Center); foreach (WPoint point in tangentPoints) { if (!Contains(point)) { return(false); } } return(true); }
/// <summary> /// Returns true if this circle entirely contains circle <paramref name='b'/>, or they exactly overlap. /// </summary> public bool Contains(WCircle b) { if (b.Radius > this.Radius) { return(false); } if (b.Radius == this.Radius) { return(b.Center == this.Center); } double d = this.Center.Distance(b.Center); return(this.Radius >= d + b.Radius); }
/// <summary> /// Returns true if any part of this wedge overlaps any part of circle <paramref name='b'/>. /// </summary> public bool Overlaps(WCircle b) { WWedge a = this; WPoint[] intersections = a.Circle.GetIntersectionPoints(b); if (intersections == null) { if (!a.Circle.ContainsOrIsContained(b)) { return(false); } } //line edge overlaps circle foreach (WLineSegment lineA in this.LineEdges) { if (b.Overlaps(lineA)) { return(true); } } //arc overlaps circle if (a.ArcOverlapsArc(new WWedge(b, 0, WCircle.DEGREES_IN_CIRCLE))) { return(true); } //wedge entirely contains circle or circle entirely contains wedge if (a.Contains(b)) { return(true); } if (b.Contains(a)) { return(true); } return(false); }
/// <param name="circle">The full circle this wedge is a part of.</param> /// <param name="degreeRange">The range of degrees this wedge covers.</param> public WWedge(WCircle circle, WRangeCircular degreeRange) : base(circle.Center, degreeRange) { Radius = circle.Radius; }
/// <param name="circle">The full circle this wedge is a part of.</param> /// <param name="degreeStart">The starting degree the wedge covers.</param> /// <param name="degreeEnd">The ending degree the wedge covers.</param> public WWedge(WCircle circle, double degreeStart, double degreeEnd) : base(circle.Center, degreeStart, degreeEnd) { Radius = circle.Radius; }