Public Group

# Simplify nodes in a grid

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

## Recommended Posts

Hello

I have a basic node system that stores points as well as the points they are connected to in my JavaScript like this:

var path    = [];


Now the end result looks something along the lines of this in my game:

The yellow dots represent the nodes stored in my path data. Now the question is how do i simplify this for when a user is building a road on the map so it automatically corrects the data.

Essentially if a user builds an intersection the nodes will update accordingly to keep the data clean and simple here is an example with the nodes in the place they should be:

The logic to do this seems quite complex and am hoping for some guidance on the best way to do this, i don't really know where to begin with adding the functionality to do this. The paths can go in 8 compass directions, N,S,E,W,NE,SE,SW and NW.

Edited by thefollower

##### Share on other sites
Quick thought, probably wrong, but is it not just if a cell has more or less than two neighbours? That covers the cases you posted at least.

##### Share on other sites

It's not readily evident what you're trying to do from your explanation.

Now the question is how do i simplify this for when a user is building a road on the map so it automatically corrects the data.

What do you mean by "simplify", and "corrects the data", what do you perceive as incorrect?

Essentially if a user builds an intersection the nodes will update accordingly to keep the data clean and simple

What do you mean by "update accordingly" and what would be "clean and simple", please define the problem more thoroughly - what is it exactly that you want to achieve? How does the current situation differ from what you'd like to achieve.

Edited by lightxbulb

##### Share on other sites

It's not readily evident what you're trying to do from your explanation.

Now the question is how do i simplify this for when a user is building a road on the map so it automatically corrects the data.

What do you mean by "simplify", and "corrects the data", what do you perceive as incorrect?

Essentially if a user builds an intersection the nodes will update accordingly to keep the data clean and simple

What do you mean by "update accordingly" and what would be "clean and simple", please define the problem more thoroughly - what is it exactly that you want to achieve? How does the current situation differ from what you'd like to achieve.

The yellow dots show how the data should be represented - as simple points with the minimal amount required for any combination of path. As you see if a user builds an intersection, 2 nodes are removed, one is added in the middle of the intersection, and 2 are added to the horizontal path. The code needs to delete and insert these automatically based on the layout of the path so then my path finding has less work to do.

##### Share on other sites

"as simple points with the minimal amount required for any combination of path." - in your case it's not the minimal amount, I could get the same image without the node in the middle, so you actually want intersection to generate nodes at the intersections? "As you see if a user builds an intersection" - define builds an intersection - does he build it manually, or do you mean that by defining 2 roads that intersect - the program should recognize this intersection? "2 nodes are removed, one is added in the middle of the intersection, and 2 are added to the horizontal path." - I lost you here, I think I get how you get the central node, but why do you remove nodes and why do you add 2 nodes to the horizontal path?

##### Share on other sites

"as simple points with the minimal amount required for any combination of path." - in your case it's not the minimal amount, I could get the same image without the node in the middle, so you actually want intersection to generate nodes at the intersections? "As you see if a user builds an intersection" - define builds an intersection - does he build it manually, or do you mean that by defining 2 roads that intersect - the program should recognize this intersection? "2 nodes are removed, one is added in the middle of the intersection, and 2 are added to the horizontal path." - I lost you here, I think I get how you get the central node, but why do you remove nodes and why do you add 2 nodes to the horizontal path?

Without the node in the middle i don't see how a given sprite would know to change direction if it was for example a corner, you need to know the node location so once the sprite hits that point you can go in a different direction. Thats why the middle node exists.

Why would i not remove the original nodes they would be useless to the new intersection? And the end nodes represent the end of the path so nodes need to be there to know where the path ends.

##### Share on other sites

Can you show the image of where the original nodes were supposed to be, before what you are talking about happens?

Edited by lightxbulb

##### Share on other sites

The first image shows the original nodes.

##### Share on other sites

And how exactly do you get the 2nd image without doing anything from the first image, it doesn't make sense at least to me. I think defining what "building an intersection" would help a lot, or you could just define the whole thing in terms of a graph so people won't have to guess what you are trying to do. Or just take some time to elaborate on exactly what you want to happen - the more concise information you give - the better an answer would people be able to give.

P.S. The terms you use are more than ambiguous, and while you may have an idea in your head of what you want to make - I can guess at least 10 scenarios from what you're saying.

Edited by lightxbulb

##### Share on other sites

Its built like a city builder when building roads in simcity for example, by the user clicking and dragging a path through the original path to create a  + shaped path.

Edited by thefollower

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5

• 14
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631431
• Total Posts
3000039
×