Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hey guys,

I was going to make a program that would find the outer edges that do not equal to null(0).

I currently have two arrays, one with all the information in it from where I will find the edges, and one of them that will point out where the edges are at.

So here's an example of what I'm trying to accomplish, and I have attempted many times but failed due to lack of performance, or lack of ideas.

Information Array:
0-0-0-0-0-0-0
0-#-#-#-#-#-0
0-#-#-0-#-#-0
0-#-#-#-#-#-0
0-#-#-#-#-#-0

If the above grid is our information array, or from where to find the edges, our edges array would result in another two dimensional array as the following:

Edges Array:
0-0-0-0-0-0-0
0-#-#-#-#-#-0
0-#-0-0-0-#-0
0-#-0-0-0-#-0
0-#-#-#-#-#-0

Now obviously, this would simply mean that I would do a basic for loop for every direction and see where it hits. At least, that's what I thought until I realised that if there is a hole:

0-0-0-0-0-0-0
0-#-#-#-#-#-0
0-0-0-#-#-#-0
0-#-0-#-#-#-0
0-#-#-#-#-#-0

It wouldn't know that there are actually objects where the "@" is located.

0-0-0-0-0-0-0
0-#-#-#-#-#-0
0-0-0-#-#-#-0
0-#-@-#-#-#-0
0-#-#-#-#-#-0

Does anyone have any clues on how to perform this action?
Posted
Comments
BillWoodruff 24-Dec-13 15:42pm    
Looking at you examples, I can't understand exactly what you mean by "edge;" could you explain a bit further ?
Deviant Sapphire 24-Dec-13 15:46pm    
Well, it's simple really. The hashtags that are filled in just like filled square have edges. Basically the goal is to find the locations of the edges(Array[ x, y]) and put those into another array. It's easy to do this with rectangles, spheres, and every shapre for that matter, however a shape that has for instance a cut-in edge also has indirect edges as shown in the last example. I have no idea how to get those.
Deviant Sapphire 24-Dec-13 15:50pm    
Here is what I mean.
http://i39.tinypic.com/2hfq654.png
The black lines are the "edges" in x,y cooardinates based on pixels.
Deviant Sapphire 24-Dec-13 15:50pm    
You wouldn't be able to find those by using only two for loops, and I have no idea how to do it otherwise.
Deviant Sapphire 24-Dec-13 15:57pm    
Also be sure not to forget that they are metaphors for real objects in a two dimensional array, from which one is null and the other one is a real object.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900