/// <summary> /// Returns a line segment with the coordinates of a chord centered on /// the given angle with the given length. /// </summary> /// <param name="angleThroughCenter">The angle that passes through the /// center of the chord, in degrees.</param> /// <param name="chordLength">The length of the chord.</param> public LineSeg2D GetChord(decimal angleThroughCenter, decimal chordLength) { LineSeg2D l = default(LineSeg2D); decimal a = 0m; // Create a right triangle where one side is half the chord length, // the other side is from the center of the circle to the midpoint // of the chord, and the hypotenuse is from the center of the circle // to the chord start point a = RightTriangle.GetAngleFromOppSideHyp(0.5m * chordLength, _radius); l.Pt1 = PointAt(angleThroughCenter - a); l.Pt2 = PointAt(angleThroughCenter + a); return(l); }
/// <summary> /// Gets the total angle on a circle of the given radius from one side of the chord to the other. /// </summary> /// <param name="chordLength">The length of the chord.</param> /// <param name="circleRadius">The radius of the circle.</param> public static decimal GetChordTotalAngle(decimal chordLength, decimal circleRadius) { if (chordLength == 0) { return(0m); } else if (chordLength > circleRadius * 2m) { throw new Exception("Chord can't fit inside a circle with the specified radius!"); } else if (chordLength == circleRadius * 2m) { return(180m); } else { return(RightTriangle.GetAngleFromOppSideHyp(0.5m * chordLength, circleRadius) * 2m); } }