Say I have a grid with 9 points:
1 2 3
4 5 6
7 8 9
Each point / node can be connected to other nodes to form segments:
1 2 3
|
|
4 5 6
| |
| |
| |
7-------8-----9
In this illustration, 1 is connected to 4, 4 is connected to 1 and 7, 7 is connected to 4 8, 8 is connected to 5 and 9, 5 is connected to 8, and 9 is connected to 8.
If I simply rendered this like this:
for each node n1
for each node n2 in n1
create segment from n1 to n2.
This would generate a lot of duplicate segments.
Would there be a way to do it so that I only create the necessary number of segments?
My goal is to be able to say, break the link between 1 and 4 and connect 1 and 5 together and regenerate the grid.
I’m trying to generate a simple city.
Thanks
The structure illustrated in your ASCII drawings is called a graph. In particular, you are trying to generate a planar graph. There are several common ways to represent a graph data structure in a computer program.
These Wikipedia links are very heavy on the mathematical theory, but I hope you find them helpful.