Polygon extends PointList implements Shape { @Reference( author = { "Carsten Steger" }, title = "On the Calculation of Moments of Polygons", type = ReferenceType.Techreport, month = "August", year = "1996", url = "http: public double[] calculateSecondMoment() { final boolean closed = isClosed(); final double area = calculateSignedArea(); if (!closed) close(); double axx = 0; double ayy = 0; double axy = 0; for (int k = 0; k < points.size() - 1; k++) { final float xk = points.get(k).getX(); final float yk = points.get(k).getY(); final float xk1 = points.get(k + 1).getX(); final float yk1 = points.get(k + 1).getY(); final float shared = xk * yk1 - xk1 * yk; axx += (xk * xk + xk * xk1 + xk1 * xk1) * shared; ayy += (yk * yk + yk * yk1 + yk1 * yk1) * shared; axy += (2 * xk * yk + xk * yk1 + xk1 * yk + 2 * xk1 * yk1) * shared; } if (!closed) open(); return new double[] { axx / (12 * area), axy / (24 * area), ayy / (12 * area) }; } Polygon();  Polygon(boolean representsHole);  Polygon(Point2d... vertices);  Polygon(Collection<? extends Point2d> vertices);  Polygon(Collection<? extends Point2d> vertices, boolean copy); List<Point2d> getVertices(); int nVertices(); boolean isClosed(); void close(); void open(); @Override boolean isInside(Point2d point); @Override Polygon clone(); Polygon difference(Polygon p); @Override double calculateArea(); double calculateSignedArea(); @Override double intersectionArea(Shape that); @Override double intersectionArea(Shape that, int nStepsPerDimension); @Override Polygon asPolygon(); void addVertex(float x, float y); void addVertex(Point2d pt); Polygon roundVertices(); boolean isEmpty(); int getNumInnerPoly(); Polygon getInnerPoly(int index); void addInnerPolygon(Polygon p, boolean inferOuter); void addInnerPolygon(Polygon p); List<Polygon> getInnerPolys(); void setIsHole(boolean isHole); boolean isHole(); @Override boolean equals(Object obj); boolean equals(Polygon p); @Override int hashCode(); @Override String toString(); Polygon intersect(Polygon p2); Polygon union(Polygon p2); Polygon xor(Polygon p2); Polygon reduceVertices(double eps); @Override Polygon transform(Matrix transform); @Override Rectangle calculateRegularBoundingBox(); @Override void translate(float x, float y); @Override void scale(float sc); @Override Polygon scaleX(float sc); @Override Polygon scaleY(float sc); @Override Polygon scaleXY(float scx, float scy); @Override void scale(Point2d centre, float sc); @Override Point2d calculateCentroid(); @Reference( author = { "Carsten Steger" }, title = "On the Calculation of Moments of Polygons", type = ReferenceType.Techreport, month = "August", year = "1996", url = "http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.29.8765&rep=rep1&type=pdf") double[] calculateFirstMoment(); @Reference( author = { "Carsten Steger" }, title = "On the Calculation of Moments of Polygons", type = ReferenceType.Techreport, month = "August", year = "1996", url = "http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.29.8765&rep=rep1&type=pdf") double[] calculateSecondMoment(); @Reference( author = { "Carsten Steger" }, title = "On the Calculation of Moments of Polygons", type = ReferenceType.Techreport, month = "August", year = "1996", url = "http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.29.8765&rep=rep1&type=pdf") double[] calculateSecondMomentCentralised(); double calculateDirection(); Ellipse toEllipse(); @Override boolean isConvex(); boolean hasNoInnerPolygons(); @Override double calculatePerimeter(); boolean isClockwise(); Polygon calculateConvexHullMelkman(); @Override RotatedRectangle minimumBoundingRectangle(); RotatedRectangle minimumBoundingRectangle(boolean assumeSimple); Point2d closestPoint(Point2d pt);  }
@Test public void testPolygonSecondMoment() { final Polygon p = new Polygon(new Point2dImpl[] { new Point2dImpl(2, 0), new Point2dImpl(0, 4), new Point2dImpl(8, 8), new Point2dImpl(10, 4), }); final double[] secondMoment = p.calculateSecondMoment(); assertEquals(secondMoment[0], 30 + 2f / 3f, 0.0001); assertEquals(secondMoment[1], 22, 0.0001); assertEquals(secondMoment[2], 18 + 2f / 3f, 0.0001); }