public class SmallestEnclosingCircleCalculator extends Object
The implementation of this class is based on:
"A randomized incremental algorithm" in:
Xu, S. Freund, R.M. Sun, J. Solution methodologies for the Smallest Enclosing Circle Problem.
Computational Optimization and Applications, volumne 25, issue 1-3, pp283-292, 2003
Calculating the exact size of the smallest enclosing circle can be computationally expensive. This class also offers an approximation of this value. The approximated radius is guaranteed to be larger or equal to the exact radius. The tighter the circles are packed, the more accurate the approximation becomes.
Examples for circle packing are given here:
To limit the impact caused by rounding issues, this class uses BigDecimals for added precision.
Modifier and Type | Field and Description |
---|---|
static boolean |
DEBUG |
static double |
PRECISION
Precision parameter
|
static boolean |
VALIDATORS_ENABLED |
Constructor and Description |
---|
SmallestEnclosingCircleCalculator() |
Modifier and Type | Method and Description |
---|---|
void |
calcExactContainer(double[] xCors,
double[] yCors,
double[] radii)
Given a set of circles identified by their x-coordinates, y-coordinates and radii, this method calculates
the smallest enclosing circle which encloses all the circles provided.
|
void |
calculateApproximateContainer(double[] xCors,
double[] yCors,
double[] radii)
Given a set of circles identified by their x-coordinates, y-coordinates and radii, this method *approximates*
the smallest enclosing circle which encloses all the circles provided.
|
double[] |
getContainerPosition()
Get the x and y coordinates of the center of the enclosing circle
|
Point2D |
getContainerPositionAsPoint()
Get the x and y coordinates of the center of the enclosing circle
|
double |
getRadius()
Get the radius of the enclosing circle
|
void |
incrementalCalcContainer(int posCircleToAdd,
double[] xCors,
double[] yCors,
double[] radii,
double xCorContainer,
double yCorContainer,
double radiusContainer)
Given are a set of old circles, a circular container which encloses these circles and a new circle.
|
public static final boolean VALIDATORS_ENABLED
public static final boolean DEBUG
public static final double PRECISION
public void calculateApproximateContainer(double[] xCors, double[] yCors, double[] radii)
xAVG=\frac{\sum_i x_i}{N}
yAVG=\frac{\sum_i y_i}{N}
R=max_i \sqrt((xAVG-x_i)^2+(yAVG-y_i)^2)+r_i
xCors
- x-coordinates of the circles to be enclosed (can be positive and negative values)yCors
- y-coordinates of the circles to be enclosed (can be positive and negative values)radii
- radii of the circles to be enclosed (must be strictly positive, circles can be of any size)public void calcExactContainer(double[] xCors, double[] yCors, double[] radii)
xCors
- x-coordinates of the circles to be enclosed (can be positive and negative values)yCors
- y-coordinates of the circles to be enclosed (can be positive and negative values)radii
- radii of the circles to be enclosed (must be strictly positive, circles can be of any size)public void incrementalCalcContainer(int posCircleToAdd, double[] xCors, double[] yCors, double[] radii, double xCorContainer, double yCorContainer, double radiusContainer)
posCircleToAdd:
- the position of the circle that is being added in the xCors/yCors/radii vectorsxCors:
- xCors of placed circles (including the circle that is being added)yCors:
- yCors of placed circles (including the circle that is being added)radii:
- radii of placed circles (including the circle that is being added)xCorContainer:
- xCor of center of existing containeryCorContainer:
- yCor of center of existing containerradiusContainer:
- : radix of existing containerpublic double getRadius()
public double[] getContainerPosition()
public Point2D getContainerPositionAsPoint()
Copyright © 2016. All rights reserved.