Hi, I'm trying to get the coordinates of the center of the ellipse used to draw any arbitrary ArcSegment. I started using the code I found here http://www.charlespetzold.com/blog/2008/01/Mathematics-of-ArcSegment.html as was suggested in a different post but it has some issues. Basically, it finds the center MOST of the time. But there are some values of Size for which the center exists, yet this algorithm fails to find it.
The code above is what I'm using to find the center but for some reason, radiusY is occasionally smaller than halfChord, which makes no sense to me because the transforms should make the ellipse a circle, and the halfchord is half the distance between 2 points on that ellipse, so how can it ever be larger than the radius?
So I guess my question is A) Is there a way to fix what I have or B) is there a better way of finding the center?
// Adjust for different radii and rotation angle
Matrix matx = new Matrix();
matx.Rotate(-angleRotation);
matx.Scale(radiusY / radiusX, 1);
pt1 = matx.Transform(pt1);
pt2 = matx.Transform(pt2);
// Get info about chord that connects both points
Point midPoint = new Point((pt1.X + pt2.X) / 2, (pt1.Y + pt2.Y) / 2);
Vector vect = pt2 - pt1;
double halfChord = vect.Length / 2;
// Get vector from chord to center
Vector vectRotated;
// (comparing two Booleans here!)
if (isLargeArc == isCounterclockwise)
vectRotated = new Vector(-vect.Y, vect.X);
else
vectRotated = new Vector(vect.Y, -vect.X);
vectRotated.Normalize();
// Distance from chord to center
double centerDistance = Math.Sqrt(radiusY * radiusY - halfChord * halfChord);
// Calculate center point
Point center = midPoint + centerDistance * vectRotated;
The code above is what I'm using to find the center but for some reason, radiusY is occasionally smaller than halfChord, which makes no sense to me because the transforms should make the ellipse a circle, and the halfchord is half the distance between 2 points on that ellipse, so how can it ever be larger than the radius?
So I guess my question is A) Is there a way to fix what I have or B) is there a better way of finding the center?