Skip to main content
GameDev.net gamedev.net
🔒 Locked

Find Perimeter Of Points

Started by aaronzim Mar 9, 2012 at 8:07 AM 2 replies 1.7k views
Original Post
aaronzim
aaronzim
Hey Guys smile.png

I'm creating a 2d game with destructible terrain. The terrain will be grid based and I have an array representing each 10 pixels of the screen populated with points or null if there is no terrain at that location. Is it possible to trace around the perimeter of the terrain like you can see in the image?
haegarr
haegarr
It is possible to find borders between cells with and without content, and to make a contour from the pieces. The first part can be done e.g. by using algorithms from voxel rendering, like marching cubes (but adapted to 2D, of course). Having determined which of and how the 4 sides of a cell are passed by borders, you can chain borders by following the border in those neighbored cells that are determined by the border configuration of the current cell.
jwezorek
jwezorek
What you're asking about is a simple case of a classical image processing problem. Just google "contour tracing" or "contour extraction". Also I have a python implementation of contour extraction in the general case here although it isn't the clearest code in the world and is overkill for what you need (I think).

You'll have to do some post-processing to clip corners to get diagonals like you want though.
aaronzim
aaronzim
Thanks! I did a google search and came across this which looks promosing. smile.png And I shall check out your code jwezoewk.

The method I currently use which doesn't work in all cases involves searching neighbouring pixels for a "candidate" next pixel, then moving to the candidate most in the direction back to the starting position.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.