unable to label voronoi polygons

17 views
Skip to first unread message

Srirama Bhamidipati

unread,
Aug 2, 2014, 7:29:57 AM8/2/14
to gama-p...@googlegroups.com
Hi,

I have generated a voronoi map and would like to label the polygons. But it was not possible, it only labels the central polygon. Could you please check what is wrong? Here the code

---------

/**

 *  voronoi

 *  Author: skbhamidipati

 *  Description: 

 */


model voronoi


/* Insert your model definition here */


global{

list<geometry> var0 <- voronoi([{10,10},{50,50},{90,90},{10,90},{90,10}]);

string dot_is_inside_which_polygon <-('');

point point_location;

reflex change_location{

point_location<-{rnd(100),rnd(100)};

}

init{

create polygons from: var0;

create dots number:1{

set location <- point_location;

}

loop p over:polygons{

if (length(dots inside(p))!=0){

dot_is_inside_which_polygon<-p.name;

write dot_is_inside_which_polygon;

}

}

}

}

species dots{

string holding_polygon;

reflex where_is_the_dot{

holding_polygon <- string(polygons overlapping(self));

write holding_polygon;

}

aspect d{

draw circle(1) color:#blue;

draw string(location.x with_precision 2)+","+string( location.y with_precision 2) +" @ "+string(dot_is_inside_which_polygon) size:3 color:#blue;

}

}

species polygons{

reflex a when:cycle=1{

write self.name;

}

aspect d {

draw  shape color:rgb('white') border:#black;

draw name size:(5) color:#blue;

}

}

experiment naam type:gui{

output {

display map type:java2D{

 

 

species polygons aspect: d;

species dots aspect: d;

 

}

}

}

---------

Patrick Taillandier

unread,
Aug 2, 2014, 12:41:58 PM8/2/14
to gama-p...@googlegroups.com
Hi,

It is due to the fact that the voronoi geometries are not limited by the world geometry (their union can be bigger than the world geometry).

You can test to modify a bit the geometries obtained by the voronoi operator to compute their intersection with the world shape:

var0 <- var0 collect (each inter shape); //before creating the polygons agents, compute the intersection between the voronoi geometries and the world geometry.

create polygons from: var0;


Cheers,


Patrick



--
You received this message because you are subscribed to the Google Groups "GAMA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
To post to this group, send email to gama-p...@googlegroups.com.
Visit this group at http://groups.google.com/group/gama-platform.
For more options, visit https://groups.google.com/d/optout.

Srirama Bhamidipati

unread,
Aug 2, 2014, 2:42:07 PM8/2/14
to gama-p...@googlegroups.com
Thank you Patrick. I was expecting GAMA to do the intersection and never thought about that. Thanks for refreshing. 
However, you suggestion results in an error, I tried as follows

list<geometry> var0 <- voronoi([{10,10},{50,50},{90,90},{10,90},{90,10}]);

var0 <-var0 collect (each inter shape);

Srirama Bhamidipati

unread,
Aug 2, 2014, 2:44:48 PM8/2/14
to gama-p...@googlegroups.com
OK Solved. Thanks :) :) 
Reply all
Reply to author
Forward
0 new messages