Commit 756be47b authored by Nico Mack's avatar Nico Mack

Added fitBoundingEllipse method

parent df110ee7
......@@ -18,6 +18,8 @@ package lu.list.itis.dkd.tui.utility;
import lu.list.itis.dkd.tui.widget.corona.ShapeFactory;
import org.apache.commons.math3.stat.regression.RegressionResults;
import org.apache.commons.math3.stat.regression.SimpleRegression;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -566,6 +568,11 @@ public class ShapeUtils {
}
// ---------------------------------------------------------------------------
/**
* @param shape
* @return
*/
// ---------------------------------------------------------------------------
public static Point getVisualCenterOf(Shape shape) {
final double precision = 1;
......@@ -681,6 +688,29 @@ public class ShapeUtils {
return grid;
}
// ---------------------------------------------------------------------------
// ellipse of the form Ax^2 + Bxy + Cy^2 + Dx +Ey = 1
// ---------------------------------------------------------------------------
public static double[] fitBoundingEllipse(Shape shape) {
List<Segment> segments = getSegments(shape);
double[] observation = new double[6];
SimpleRegression leastSquare = new SimpleRegression();
for (Segment segment : segments) {
observation[0] = segment.x0 * segment.x0; // x2
observation[1] = segment.x0 * segment.y0; // x * y
observation[2] = segment.y0 * segment.y0; // y2
observation[3] = segment.x0; // x
observation[4] = segment.y0; // y
leastSquare.addObservation(observation, 1);
}
RegressionResults results = leastSquare.regress();
return results.getParameterEstimates();
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment