How would I position nodes inside a polygon to be as equally spaced as possible?

Hey guys, I am currently modifying the demo travelling salesman problem included with matlab and was wondering how I would place nodes within a polygon which would be as equally spaced as possible, unlike the "random nodes" the demo version uses. I would also like nodes to be on the perimeter of the polygon also being equally spaced. The nodes should be no further than a set distance apart, but it is ok if some nodes are slightly closer. I will be working with relatively straightforward polygons such as squares and rectangles but would like to automate this process as much as possible so I could load different perimeters. Any help is greatly appreciated :)

Risposte (1)

You might try John D'Errico's interparc: http://www.mathworks.com/matlabcentral/fileexchange/34874-interparc This will handles nodes along the perimeter of the polygon. To get inside, you can digitize the polygon and then call imerode() to "eat away" at the polygon and make it smaller, or just use a scaling factor to "pull in" the points towards the centroid. Then call interparc() on the smaller perimeter.

2 Commenti

So what you are essentially saying if I understand this correctly is to continually shrink the polygon equally spacing the nodes along the perimeter each time, and eventually it should fill the whole polygon yes? Thanks, I'll have a look at this, hopefully I can still apply the travelling salesman problem to these nodes.
Well that's one way. You might be able to do it easier if you call the distance transform, bwdist(). I'm not sure why you need a uniform array of nodes inside the polygon route of the traveling salesman, but whatever.... Anyway, what's wrong with just having the polygon inside be a simple rectangular array?

Accedi per commentare.

Richiesto:

il 3 Feb 2016

Commentato:

il 3 Feb 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by