Polygon extends PointList implements Shape { public double calculateDirection() { final double[] secondMoment = calculateSecondMomentCentralised(); final double u20 = secondMoment[0]; final double u02 = secondMoment[1]; final double u11 = secondMoment[2]; final double theta = 0.5 * Math.atan2((2 * u11), (u20 - u02)); return theta; } 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 testPolygonDirection() { 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 direction = p.calculateDirection(); System.out.println(direction); }