Source
code for Fitting Ellipses
April 2015
We are interested in
creating computer-based tools to help design engineers during the first stage
of the design process, known as conceptual design. Hence, we develop
Sketch-Based Modelling
(SBM) systems. The first stage in our approach for SBM is converting the input
sketch into a line drawing.
At this end, we need to determine whether or not every single stroke depicts an
elliptic arc.
Attached is a C++
implementation of the code of the new Fitting Ellipses (FE) algorithm.
You can download the FE code from
here.
The input to the FE code is a 2D stroke, which includes
a list of coordinates of points sampled when moving the cursor.
The time interval is also stored (as it is used for some finding corners
approaches).
The output is the
information of the elliptic arc that better fits the stroke.
The information is stored in an instance of the class CArc,
where every Arc instance includes:
double Centre_x,
Centre_y
double Radius_a, Radius_b; // The
semi-axes lengths
double
Rotation; // Counterclockwise angle of
rotation from the x-axis to the major axis
double
Focus1_x, Focus1_y
double
Focus2_x, Focus2_y
double StartAngle; //Relative
to the local system. Absolute angle is StrarAngle+Rotation
double EndAngle;
//Relative to the local system. Absolute angle is EndAngle+Rotation
The figure of merit
of the fitting is also returned (1 is perfect fit and 0 is no fit at all).
The approach is
encapsulated into a main class CFitEllipse. Complementary code is also provided.
Reader must note that
the fitting ellipses approach includes detection of corner points.
The algorithms used to detect corner are provided as black boxes.
This approach for
fitting ellipses is extensively described in:
Company P., Plumed R. and Varley P.A.C. (2015).
A fast approach for perceptually-based fitting strokes into
elliptical arcs.
The Visual Computer Journal, 31(6), pp. 775-785.
To help understanding
how the code works, and in order to offer a test environment too, the following
main
file is also provided:
·
FitEllipseMain.cpp, and its header FitEllipseMain.h.
This main function
reads data contained in an example named as “example.stk”.
Other examples are provided in the corresponding folder.
Finally, we must
highlight that the code was written to make it readable. Efficiency never was a
goal.
********************************************************************************************
The FE code is free
software. But if you find it useful for your own research,
please cite our paper:
Company P., Plumed R. and Varley P.A.C. (2015).
A fast approach for perceptually-based fitting strokes into
elliptical arcs.
The Visual Computer Journal, 31(6), pp. 775-785.
********************************************************************************************