Determine whether a spline curve describes an elliptical arc

I'm currently writing software which analyses STEP files to hunt for engineered parts with particular shapes. The software uses Open Cascade which presents me with topological and geometrical objects in a BREP representation. When this gives me explicit cylindrical and toroidal surfaces, and explicit circles, ellipses and lines, I can accomplish my task fairly easily. The problem arises when shapes that I know are meant to be circles or ellipses–and were probably drawn with that intent in whatever CAD software produced the STEP file–are represented in the BREP format as spline curves of various degree, which approximate the desired shapes perfectly well visually, and for manufacturing, but which lose the original design intent.

Curves (or "edges") in the BREP format are parameterized, and I can get positions, tangents, curvature and centre of curvature at any parameter value. So actually, detecting straight lines is easy–I just look for zero curvature along the length–and similarly for circular arcs, where I can just look for constant curvature at a number of sampled parameter values. My question is, given the same information, how can I detect elliptical arcs (they might not be complete ellipses) that are not circular? What should I be looking for? Ideally, I want the center of the ellipse (or the two foci) and the major and minor radii, but the crucial output would be the center itself.

Googling just turns up a mountain of results about doing the opposite, i.e. approximating conics using splines (as the CAD software does to begin with). Nobody seems to want to reverse the process!


Solution 1:

Let $AB$ be any chord of the ellipse, $a$, $b$ the tangents at its endpoints and $P$ the intersection of $a$ with $b$. If $M$ is the midpoint of $AB$, then line $PM$ passes through the center of the ellipse.

Hence you can find the center from any two chords. And you can check with other chords if you get the same result (otherwise the curve is not an ellipse).

Moreover, the midpoints of any two parallel chords of an ellipse are aligned with the center: this is another property which could be useful to find the center of the ellipse.