singa-bio/singa

VoronoiRelaxation

Opened this issue · 2 comments

Znbne commented

Hi
I have a set of vertices which make a polygon. I created the polygon as follows:

private static VertexPolygon simplePolygon;
private List points;
simplePolygon = new VertexPolygon(points.toArray(new Vector2D[0]));

I need to distribute a specific number (say n) of points over the polygon with the equal distance or fair distribution (or select n points within the polygon). As far as I know, to do this one approach is to split the original polygon into 'n' equal area sub-polygons and select their center as the intended points. And the other one is VoronoiRelaxation. I tried the second solution using your library. But the method "relax" only accepts (GraphType graph, Rectangle boundingBox) and (VoronoiDiagram) which I do not know how can I convert my original polygon to this types. I probed internet and javadoc for any code example of related to my problem but I could not find anything useful.
I would be great if you guide me in this case with code examples or anything useful.
Thank you.

Hi Znbne,
sorry for the delayed answer.
Are you looking for the arrangement of points in arbitrary polygons? Currently, SiNGA only offers Voronoi relaxation for rectangular bounding boxes. You can achive that by using the following code:

// create new rectangle from point (0,0) to (200,200)
Rectangle boundingBox = new Rectangle(200, 200);
// create random points within the rectangle
List<Vector2D> points = Vectors2D.generateMultipleRandom2DVectors(25, boundingBox);
// generate initial voronoi diagram from the points
VoronoiDiagram voronoiDiagram = VoronoiGenerator.generateVoronoiDiagram(points, boundingBox);
// run relaxation 10 times
int runs = 10;
for (int i = 0; i < runs; i++) {
    // perform one round of relaxation
    List<Vector2D> relaxedSites = VoronoiRelaxation.relax(voronoiDiagram);
    // create new voronoi diagram using the relaxed sites
    voronoiDiagram = VoronoiGenerator.generateVoronoiDiagram(relaxedSites, boundingBox);
}

All the best
Christoph

Znbne commented

Thank you Christoph for your guidance. Exactly I want to distribute n points with equal distances in a polygon.