Class Polygon
java.lang.Object
davidmarino.model.mapmodels.Polygon
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
applyNoisyBorder
(double diversion) Adds a new point to this polygon and to all neighbors.static Polygon
computeVoronoiCell
(Point site, ArrayList<Point> allSites) Generates a voronoi cell.static void
drawFilledPolygon
(Graphics2D g2, Polygon polygon, Color color) Renders a polygon.static void
drawFilledPolygons
(Graphics2D g2, ArrayList<Polygon> polygons) Renders set of filled polygons.static void
drawPolygonBorder
(Graphics2D g2, Polygon polygon, Color color) Renders polygons borderstatic void
drawPolygonBorders
(Graphics2D g2, ArrayList<Polygon> polygons, Color color) Renders set of polygon boarders.boolean
static void
findNeighbors
(ArrayList<Polygon> polygons) Finds neighbors of all polygons.Finds the quadrilaterals that exists between this polygon and its neighbors.generateVoronoiPolygons
(ArrayList<Point> sitePoints) Generates voronoi polygons given the site points.static Polygon
getBoundingBox
(int width, int height) Generates the initial polygon that is the size of the image.toString()
-
Field Details
-
vertices
-
neighbors
-
site
The point that this polygon orientates itself
-
-
Constructor Details
-
Polygon
-
Polygon
-
Polygon
-
-
Method Details
-
getBoundingBox
Generates the initial polygon that is the size of the image.- Parameters:
width
- of the imageheight
- of the image- Returns:
Polygon
-
computeVoronoiCell
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 generatedallSites
- is a list of all sites that exist- Returns:
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
-
findNeighbors
-
drawFilledPolygon
Renders a polygon.- Parameters:
g2
- is the render librarypolygon
- to be renderedcolor
- of the filled polygon
-
drawPolygonBorder
Renders polygons border- Parameters:
g2
- is the render librarypolygon
- to be renderedcolor
- of the polygon border
-
drawFilledPolygons
Renders set of filled polygons. Colors based on z value of Polygon.- Parameters:
g2
- is the render librarypolygons
- to be rendered
-
drawPolygonBorders
Renders set of polygon boarders.- Parameters:
g2
- is the render librarypolygons
- to be renderedcolor
- of the polygon boarder
-
toString
-
equals
-