• Advertisement
Sign in to follow this  

Find Perimeter Of Points

This topic is 2235 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement