Package worldBuilder
Class Mesh
- java.lang.Object
-
- worldBuilder.Mesh
-
public class Mesh extends java.lang.Object
a set of irregularly spaced interconnected points: all (x,y,z) coordinates are relative to the center of a (-0.5 to +0.5) unit-cube. Once created, the mesh (collection of connected points) does not change, but the attributes of the individual points (e.g. altitude and hydration) do evolve over time). The intent is that all other maps, even though much more detailed than the mesh, should be deterministically derivable from the mesh and its parameters. Notes on generation: O'Leary observed that a map created on a square grid never loses its regularity, so he wanted to build the map on an irregular grid. But he found randomly chosen grids to be too irregular. Mesh generation implements his compromise. 1. He starts by generating N completely randomly chosen points. But these turn out to be a little to clumpy, so he smoothes them out (improves them) by finding the Voronoi polygons around those points and using their vertices. 2. He uses those (improved) points as the centers for a second Voronoi tesselation, whose vertices become the map points, and whose edges become a connected mesh (each internal point has three neighbors).
-
-
Constructor Summary
Constructors Constructor Description Mesh()
create an initial (empty) array of MeshPoints
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MeshPoint
choosePoint(double x, double y)
find the MeshPoint closest to a map coordinatevoid
makeMesh(MeshPoint[] points)
turn a set of points into a meshMeshPoint[]
makePoints(int numpoints)
create a set of mesh pointsvoid
read(java.lang.String filename)
read mesh of MapPoints from a file
-
-
-
Field Detail
-
vertices
public MeshPoint[] vertices
the MeshPoints in this Mesh
-
-
Method Detail
-
makePoints
public MeshPoint[] makePoints(int numpoints)
create a set of mesh points- Parameters:
numpoints
- in the desired mesh- Returns:
- array of new MeshPoints
-
read
public void read(java.lang.String filename)
read mesh of MapPoints from a file- Parameters:
filename
- of input file
-
choosePoint
public MeshPoint choosePoint(double x, double y)
find the MeshPoint closest to a map coordinate- Parameters:
x
- desired map coordinate (e.g. -0.5 to 0.5)y
- desired map coordinate (e.g. -0.5 to 0.5)- Returns:
- MeshPoint (closest)
-
makeMesh
public void makeMesh(MeshPoint[] points)
turn a set of points into a mesh- Parameters:
points
- set of (not yet connected) MeshPoints compute the Voronoi tesselation for each edge (that is within the box) add each new end to our vertex list add the edge as path in/out of each vertex NOTE: that the original points are replaced with the vertices of the corresponding Voronoi polygons.
-
-