/// <summary> /// Assignment given a straight line defining the end points and a point on the arc. /// </summary> /// <param name="ArcLine">The line defining the start and end point of the arc.</param> /// <param name="ptOnArc">A point on the arc.</param> public void Set(C2DLine ArcLine, C2DPoint ptOnArc) { Line.Set(ArcLine); C2DPoint ptTo = new C2DPoint(Line.GetPointTo()); C2DCircle Circle = new C2DCircle(); Circle.SetCircumscribed(Line.point, ptTo, ptOnArc); Radius = Line.point.Distance(Circle.Centre); ArcOnRight = Line.IsOnRight(ptOnArc); CentreOnRight = Line.IsOnRight(Circle.Centre); }
/// <summary> /// Assignment given a straight line defining the end points and a point on the arc. /// </summary> /// <param name="ArcLine">The line defining the start and end point of the arc.</param> /// <param name="ptOnArc">A point on the arc.</param> public void Set(C2DLine ArcLine, C2DPoint ptOnArc) { Line.Set(ArcLine); C2DPoint ptTo = new C2DPoint(Line.GetPointTo()); C2DCircle Circle = new C2DCircle(); Circle.SetCircumscribed( Line.point , ptTo, ptOnArc) ; Radius = Line.point.Distance( Circle.Centre ); ArcOnRight = Line.IsOnRight(ptOnArc); CentreOnRight = Line.IsOnRight(Circle.Centre); }
/// <summary> /// Gets the minimum bounding circle. /// </summary> /// <param name="Circle">Ouput. The Circle.</param> public void GetBoundingCircle(C2DCircle Circle) { if (this.Count < 3) { if (this.Count == 2) { Circle.SetMinimum(this[0], this[1]); } else if (this.Count == 1) { Circle.Set(this[0], 0); } else { Debug.Assert(false, "Point set with no points. Cannot calculate bounding circle."); } return; } int nIndx1 = 0; int nIndx2 = 0;; int nIndx3 = 0;; double dDist = 0;; // First get the points that are furthest away from each other. GetExtremePoints(ref nIndx1, ref nIndx2, ref dDist); // Set the circle to bound these. Circle.SetMinimum(this[nIndx1], this[nIndx2]); // Set up a flag to show if we are circumscibed. (Once we are, we always will be). bool bCircum = false; // Cycle through and if any points aren't in the circle, then set the circle to be circumscribed. for (int i = 0; i < Count; i++) { if (i != nIndx1 && i != nIndx2) { if (!Circle.Contains(this[i])) { nIndx3 = i; Circle.SetCircumscribed(this[nIndx1], this[nIndx2], this[nIndx3]); bCircum = true; // Break out and try again. break; } } } // If we didn't succeed first time then go through again setting it to be circumscribed every time. if (bCircum) { for (int i = 0; i < Count; i++) { if (i != nIndx1 && i != nIndx2 && i != nIndx3) { if (!Circle.Contains(this[i])) { double Dist1 = this[i].Distance(this[nIndx1]); double Dist2 = this[i].Distance(this[nIndx2]); double Dist3 = this[i].Distance(this[nIndx3]); if (Dist1 < Dist2 && Dist1 < Dist3) { // Closest to point 1 so elimitate this nIndx1 = i; } else if (Dist2 < Dist3) { // Closest to point 2 so elimitate this nIndx2 = i; } else { // Closest to point 3 so elimitate this nIndx3 = i; } Circle.SetCircumscribed(this[nIndx1], this[nIndx2], this[nIndx3]); } } } } }