I need to define an object (or a region) that is kind of "blob" shaped on a discrete gridmap. It should look something like this:
where the red region denotes the center point (these are just ideas, any blobby shape will work as long as it can be varied randomly). My idea so far was to iteratively increment the angle from starting point (=0 degrees) to 360 degrees and use trigonometry to calculate the outer points of a circle (which will result in the unit circle if the radius = 1 = const). I then used Bresenham's line algorithm (remember: we are moving on a discrete grid) to calculate the line that connects the center of the circle and the outer point I just came up with. My idea was that if I could vary the radius somewhat, I could create these blobby shapes. What I've come up with so far gives me nice shapes, they're just not really "blobby" though. Here's my code (note that x0
and y0
mark the center point of my gridmap, plotBresenham
just puts all 1s
in the regions so the gridmap can be visualized):
double radius = 10;
for(int alpha=0; alpha<360; alpha++) {
double x = cos(alpha*M_PI/180.0)*radius;
double y = sin(alpha*M_PI/180.0)*radius;
if(alpha<45) radius+=0.5;
else if(alpha<90) radius-=0.5;
else if(alpha<135) radius+=0.5;
else if(alpha<180) radius-=0.5;
else if(alpha<225) radius+=0.5;
else if(alpha<270) radius-=0.5;
else if(alpha<315) radius+=0.5;
else radius-=0.5;
plotBresenhamLine(x0,y0,x,y)
}
The result looks like this:
Sorry for the crude drawing. Programming language is C++, but I think the approach doesn't really depend on the language used. Any tips / help / guidance on how I can create shapes that resemble the ones I need more? Or even a Framework that does stuff like this for you? For me, it's just important to have the coordinates of the points within, to put them into my gridmap.
rand()
in there? – Chemism