@Test public void testRegularPolygon() { for (int sides = 3; sides < 12; sides++) { Polygon p = new RegularPolygon(sides); AssertJUnit.assertTrue(p.npoints == sides); int ox = 0; int oy = 0; for (int pt = 0; pt < sides; pt++) { ox += p.xpoints[pt]; oy += p.ypoints[pt]; } ox /= sides; oy /= sides; double dist[] = new double[sides]; double length[] = new double[sides]; int dx, dy; for (int pt = 0; pt < sides; pt++) { dx = p.xpoints[pt] - ox; dy = p.ypoints[pt] - oy; dist[pt] = Math.sqrt((double) (dx*dx + dy*dy)); dx = p.xpoints[(pt+1)%sides] - p.xpoints[pt]; dy = p.ypoints[(pt+1)%sides] - p.ypoints[pt]; length[pt] = Math.sqrt((double) (dx*dx + dy*dy)); AssertJUnit.assertTrue(Math.abs(dist[pt] - dist[0]) / dist[0] < 0.01 ); AssertJUnit.assertTrue(Math.abs(length[pt] - length[0]) / length[0] < 0.01 ); } } }
public RegularPolygon(int sides) { super(); double delta = Math.PI * 2 / (double) sides; for (double r = 0.0; r < Math.PI * 2 - (delta/2); r += delta) { this.addPoint((int) ( Math.sin(r) * 1000.0), (int) (-Math.cos(r) * 1000.0)); } }
RegularPolygon extends Polygon { public RegularPolygon(int sides) { super(); double delta = Math.PI * 2 / (double) sides; for (double r = 0.0; r < Math.PI * 2 - (delta/2); r += delta) { this.addPoint((int) ( Math.sin(r) * 1000.0), (int) (-Math.cos(r) * 1000.0)); } } }
RegularPolygon extends Polygon { public RegularPolygon(int sides) { super(); double delta = Math.PI * 2 / (double) sides; for (double r = 0.0; r < Math.PI * 2 - (delta/2); r += delta) { this.addPoint((int) ( Math.sin(r) * 1000.0), (int) (-Math.cos(r) * 1000.0)); } } RegularPolygon(int sides); }
RegularPolygon extends Polygon { public RegularPolygon(int sides) { super(); double delta = Math.PI * 2 / (double) sides; for (double r = 0.0; r < Math.PI * 2 - (delta/2); r += delta) { this.addPoint((int) ( Math.sin(r) * 1000.0), (int) (-Math.cos(r) * 1000.0)); } } RegularPolygon(int sides);  }
RegularPolygon extends Polygon { public RegularPolygon(int sides) { super(); double delta = Math.PI * 2 / (double) sides; for (double r = 0.0; r < Math.PI * 2 - (delta/2); r += delta) { this.addPoint((int) ( Math.sin(r) * 1000.0), (int) (-Math.cos(r) * 1000.0)); } } RegularPolygon(int sides);   }