Class Polygon2d

    • Constructor Detail

      • Polygon2d

        public Polygon2d​(double[] x,
                         double[] y)
                  throws DrawRuntimeException
        Construct a new Polygon2d.
        Parameters:
        x - double[]; the x coordinates of the points
        y - double[]; the y coordinates of the points
        Throws:
        DrawRuntimeException - when any two successive points are equal, or when there are too few points
      • Polygon2d

        public Polygon2d​(Point2d point1,
                         Point2d point2,
                         Point2d... otherPoints)
                  throws NullPointerException,
                         DrawRuntimeException
        Construct a new Polygon2d.
        Parameters:
        point1 - Point2d; the first point of the new Polygon2d
        point2 - Point2d; the second point of the new Polygon2d
        otherPoints - Point2d[]; all remaining points of the new Polygon2d (may be null)
        Throws:
        NullPointerException - when point1 or point2 is null
        DrawRuntimeException - when point1 is equal to the last point of otherPoints, or any two successive points are equal
      • Polygon2d

        public Polygon2d​(Iterator<Point2d> iterator)
        Construct a new Polygon2d from an iterator that yields Point2d.
        Parameters:
        iterator - Iterator<Point2d>; the iterator
      • Polygon2d

        public Polygon2d​(boolean filterDuplicates,
                         Point2d... points)
                  throws DrawRuntimeException
        Create a new Polygon2d, optionally filtering out repeating successive points.
        Parameters:
        filterDuplicates - boolean; if true; filter out successive repeated points; otherwise do not filter
        points - Point2d...; the coordinates of the polygon as Point2d
        Throws:
        DrawRuntimeException - when number of points < 2
      • Polygon2d

        public Polygon2d​(boolean filterDuplicates,
                         List<Point2d> pointList)
                  throws DrawRuntimeException
        Create a new Polygon2d, optionally filtering out repeating successive points.
        Parameters:
        filterDuplicates - boolean; if true; filter out successive repeated points; otherwise do not filter
        pointList - List<Point2d>; list of the coordinates of the line as Point3d; any duplicate points in this list are removed (this method may modify the provided list)
        Throws:
        DrawRuntimeException - when number of non-equal points < 2
    • Method Detail

      • isConvex

        public final boolean isConvex()
        Determine if this Polygon2d is convex. Returns bogus result for self-intersecting polygons. Derived from http://paulbourke.net/geometry/polygonmesh/source2.c
        Returns:
        boolean; true if this Polygon2d is convex; false if this Polygon2d is concave
      • contains

        public boolean contains​(Point2d point)
        Determine if a point is inside this Polygon. Returns bogus results for self-intersecting polygons.
        Parameters:
        point - Point2d; the point
        Returns:
        boolean; true if the point is inside this polygon, false if the point is outside this polygon. Results are ill-defined for points on the edges of this Polygon.
      • contains

        public boolean contains​(double x,
                                double y)
        Determine if a point is inside this Polygon. Returns bogus results for self-intersecting polygons. Derived from http://paulbourke.net/geometry/polygonmesh/
        Parameters:
        x - double; the x-coordinate of the point
        y - double; the y-coordinate of the point
        Returns:
        boolean; true if the point is inside this polygon, false if the point is outside this polygon. Results are ill-defined for points on the edges of this Polygon.
      • surface

        public double surface()
        Compute the surface of this Polygon2d. Sign of the result reflects the winding-ness of this this Polygon2d. If this Polygon2d self-intersects, the result is bogus.
        Returns:
        double; the surface of this Polygon2d
      • getSegment

        public LineSegment2d getSegment​(int index)
        Extract one LineSegment of this PolyLine, or Polygon.
        Specified by:
        getSegment in interface PolyLine<PolyLine2d,​Point2d,​Ray2d,​LineSegment2d>
        Overrides:
        getSegment in class PolyLine2d
        Parameters:
        index - int; the rank number of the segment; must be in range 0..Size() - 2 for PolyLine, or 0.. Size() - 1 for Polygon.
        Returns:
        LS; the LineSegment that connects point index to point index + 1
      • reverse

        public Polygon2d reverse()
        Construct a new PolyLine with all points of this PolyLine in reverse order.
        Returns:
        L; the new PolyLine
      • toPlot

        public final String toPlot()
        Convert this PolyLine3D to Peter's plot format.
        Overrides:
        toPlot in class PolyLine2d
        Returns:
        Peter's format plot output
      • toString

        public final String toString()
        Produce a string describing the Drawable using default conversion for the (double) coordinate values. Regrettably, it is not allowed to provide a default implementation here.
        Specified by:
        toString in interface Drawable<Point2d>
        Overrides:
        toString in class PolyLine2d
        Returns:
        String; a string describing the Drawable
      • toString

        public String toString​(String doubleFormat,
                               boolean doNotIncludeClassName)
        Produce a String describing the Drawable.
        Specified by:
        toString in interface Drawable<Point2d>
        Overrides:
        toString in class PolyLine2d
        Parameters:
        doubleFormat - String; a format string (something like "%6.3f") which will be used to render every coordinate value)
        doNotIncludeClassName - boolean; if true; the output of toString is not prefixed by the class name. This is useful for concatenating the textual representation of lots of Drawables (e.g. an array, or a List).
        Returns:
        String; textual representation of the Drawable