- #1

- 74

- 0

**1. Deriving the major and minor axis of an ellipse from conjugate diameters points**

**Current solution:**

Code:

```
double x1 = Diameter1.X - Center.X;
double y1 = Diameter1.Y - Center.Y;
double x2 = Diameter2.X - Center.X;
double y2 = Diameter2.Y - Center.Y;
double xc = (x2 + y1) / 2;
double yc = (y2 - x1) / 2;
double theta = Math.Atan2(yc - y2, x2 - xc);
double phi = Math.Atan2(yc, xc);
double d = xc / Math.Cos(phi);
double yu = yc + d * Math.Sin(theta);
double xv = xc + d * Math.Cos(theta);
double yv = yc - d * Math.Sin(theta);
double alpha = Math.Atan2(yv, xv);
a = (yu - y2) / Math.Sin(theta);
b = 0;
double SemiDiag1 = GraphicTools.GetRadius(Center, Diameter1);
double SemiDiag2 = GraphicTools.GetRadius(Center, Diameter2);
if (a != 0 && !double.IsNaN(a))
{
b = Math.Sqrt((Math.Pow(SemiDiag1, 2) + Math.Pow(SemiDiag2, 2)) - Math.Pow(a, 2));
}
else
{
b = d;
a = Math.Sqrt((Math.Pow(SemiDiag1, 2) + Math.Pow(SemiDiag2, 2)) - Math.Pow(b, 2));
}
```

All other angles the function works perfectly. The alternative process where a = 0 or a = NaN is inaccurate or completely dysfunctional. How does one treat the angles that don't work?

Last edited by a moderator: