Java Utililty Methods Geometry Polygon

List of utility methods to do Geometry Polygon

Description

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

Method

booleanboundingTest(Polygon p, int x, int y, int w, int h)
bounding Test
rect.setBounds(x, y, w, h);
return p.intersects(rect);
booleaninside_polygon(float[] xpts, float[] ypts, double ptx, double pty)
Tests if a point is inside a polygon.
int j, inside_flag = 0;
int numverts = xpts.length;
if (numverts <= 2)
    return false;
Point2D vtx0 = new Point2D.Float(), vtx1 = new Point2D.Float();
double dv0; 
int crossings = 0;
boolean xflag0 = false, yflag0 = false, yflag1 = false;
...
PolygonmakeArea(Polygon polygon, int steps, int dX, int dY)
make Area
for (int i = steps - 1; i >= 0; --i) {
    polygon.addPoint(polygon.xpoints[i] + dX, polygon.ypoints[i] + dY);
return polygon;
intpolyArea(Polygon target)
poly Area
int sum = 0;
for (int i = 0; i < target.npoints; i++) {
    sum = sum + target.xpoints[i] * target.ypoints[(i + 1) % target.npoints]
            - target.ypoints[i] * target.xpoints[(i + 1) % target.npoints];
return Math.abs(sum / 2);
ShaperegularPolygon(int sides, double x, double y, double width, double height)
regular Polygon
Path2D poly = new Path2D.Double(Path2D.WIND_EVEN_ODD, 12);
width = width / 2;
height = height / 2;
x = x + width;
y = y + height;
Point2D.Double points[] = new Point2D.Double[sides];
for (int i = 0; i < sides; i++) {
    double x1 = circleX(sides, i) * width + x;
...
java.awt.PolygonsparsifyPolygon(java.awt.Polygon p, double minDistance)
sparsify Polygon
int n = p.npoints;
int[] xs = p.xpoints;
ArrayList<Integer> nxs = new ArrayList<Integer>(n);
int[] ys = p.ypoints;
ArrayList<Integer> nys = new ArrayList<Integer>(n);
nxs.add(xs[0]);
nys.add(ys[0]);
int px = xs[0];
...