Class Polygon

java.lang.Object
davidmarino.model.mapmodels.Polygon

public class Polygon extends Object
Class Polygon used to create a voronoi diagram. This diagram creates natural looking polygons that can be used to render maps. For more details about voronoi diagrams look here https://en.wikipedia.org/wiki/Voronoi_diagram
  • Field Details

    • vertices

      public ArrayList<Point> vertices
      Vertices of the polygon. 2 invalid input: '<' ∣S∣ invalid input: '<'
    • neighbors

      public HashSet<Polygon> neighbors
      Polygons that share an edge with this polygon
    • site

      public Point site
      The point that this polygon orientates itself
  • Constructor Details

    • Polygon

      public Polygon(ArrayList<Point> vertices, Point site)
      Polygon constructor with no neighbors.
      Parameters:
      vertices - are the points of the polygon
      site - is the point this polygon is orientated
    • Polygon

      public Polygon(ArrayList<Point> vertices)
      Polygon constructor with no neighbors or site. Used when doing calculations where site is not needed such as when creating noisy borders.
      Parameters:
      vertices - are the points of the polygon
    • Polygon

      public Polygon(ArrayList<Point> vertices, HashSet<Polygon> neighbors, Point site)
      Polygon copy constructor
      Parameters:
      vertices - are the points of the polygon
      neighbors - are the polygons that this polygon shares a border with
      site - is the point this polygon is orientated
  • Method Details

    • getBoundingBox

      public static Polygon getBoundingBox(int width, int height)
      Generates the initial polygon that is the size of the image.
      Parameters:
      width - of the image
      height - of the image
      Returns:
      Polygon
    • computeVoronoiCell

      public static Polygon computeVoronoiCell(Point site, ArrayList<Point> allSites)
      Generates a voronoi cell. First creates the initial bounding box polygon. Next clips the polygon based on the bisector of this polygons site and all other sites.
      Parameters:
      site - of the vertex being generated
      allSites - is a list of all sites that exist
      Returns:
      Polygon
    • findQuadrilaterals

      public ArrayList<Polygon> findQuadrilaterals()
      Finds the quadrilaterals that exists between this polygon and its neighbors. The quadrilaterals are made of this site and the current neighbor and their intersection points. The number of quadrilaterals found will always be the size of the number of neighbors a polygon has.
      Returns:
      ArrayList<Polygon>
    • applyNoisyBorder

      public void applyNoisyBorder(double diversion)
      Adds a new point to this polygon and to all neighbors. The new point is the result of the midpoint displacement to add noise to the borderlines.
      Parameters:
      diversion - is the distance to skew the line from 0 to 1
    • generateVoronoiPolygons

      public static ArrayList<Polygon> generateVoronoiPolygons(ArrayList<Point> sitePoints)
      Generates voronoi polygons given the site points.
      Parameters:
      sitePoints - to determine Voronoi polygon
      Returns:
      ArrayList<Polygon>
    • findNeighbors

      public static void findNeighbors(ArrayList<Polygon> polygons)
      Finds neighbors of all polygons.
      Parameters:
      polygons - to match as neighbors
    • drawFilledPolygon

      public static void drawFilledPolygon(Graphics2D g2, Polygon polygon, Color color)
      Renders a polygon.
      Parameters:
      g2 - is the render library
      polygon - to be rendered
      color - of the filled polygon
    • drawPolygonBorder

      public static void drawPolygonBorder(Graphics2D g2, Polygon polygon, Color color)
      Renders polygons border
      Parameters:
      g2 - is the render library
      polygon - to be rendered
      color - of the polygon border
    • drawFilledPolygons

      public static void drawFilledPolygons(Graphics2D g2, ArrayList<Polygon> polygons)
      Renders set of filled polygons. Colors based on z value of Polygon.
      Parameters:
      g2 - is the render library
      polygons - to be rendered
    • drawPolygonBorders

      public static void drawPolygonBorders(Graphics2D g2, ArrayList<Polygon> polygons, Color color)
      Renders set of polygon boarders.
      Parameters:
      g2 - is the render library
      polygons - to be rendered
      color - of the polygon boarder
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object