Java Utililty Methods Geometry Circle

List of utility methods to do Geometry Circle

Description

The list of methods to do Geometry Circle are organized into topic(s).

Method

Polygoncircle2poly(float x, float y, float radius)
circlepoly
float dphi = 2.0f / radius;
int nangles = (int) ((2.0f * (float) Math.PI) / dphi);
int[] xpts = new int[nangles];
int[] ypts = new int[nangles];
for (int i = 0; i < nangles; i++) {
    float phi = dphi * i;
    xpts[i] = (int) (radius * (float) Math.cos(phi) + x);
    ypts[i] = (int) (radius * (float) Math.sin(phi) + y);
...
ShapecircleArrow(double size)
circle Arrow
Ellipse2D circle = new Ellipse2D.Double(-size, -size / 2.0, size, size);
return circle;
Point2DcircleCentre(double x1, double y1, double x2, double y2, double x3, double y3)
circle Centre
x2 -= x1;
x3 -= x1;
y2 -= y1;
y3 -= y1;
final double sq2 = (x2 * x2 + y2 * y2);
final double sq3 = (x3 * x3 + y3 * y3);
final double x = (y2 * sq3 - y3 * sq2) / (y2 * x3 - y3 * x2);
return new Point2D.Double(x1 + 0.5 * x, y1 + 0.5 * (sq2 - x * x2) / y2);
...
Point2D.DoublecircleCentre(double x1, double y1, double x2, double y2, double x3, double y3)
Returns a circle passing by the 3 given points.
x2 -= x1;
x3 -= x1;
y2 -= y1;
y3 -= y1;
final double sq2 = (x2 * x2 + y2 * y2);
final double sq3 = (x3 * x3 + y3 * y3);
final double x = (y2 * sq3 - y3 * sq2) / (y2 * x3 - y3 * x2);
return new Point2D.Double(x1 + 0.5 * x, y1 + 0.5 * (sq2 - x * x2) / y2);
...
PolygonpCircle(int x, int y, int r)
returns a polygon approximation to a circle of radius r at location x, y
Polygon p = new Polygon();
for (int k = -r; k < r; k += 1) {
    int m = x + k;
    int n = (int) Math.sqrt(r * r - k * k);
    p.addPoint(m, y + n);
for (int k = r; k > -r; k -= 1) {
    int m = x + k;
...