Detection of connected areas in a map

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Gopiandcoshow
Prole
Posts: 1
Joined: Thu Mar 12, 2015 5:02 am

Detection of connected areas in a map

Post by Gopiandcoshow »

Hello all,
I am making a simulation of a pathfinding robot for a project I am working on - there are three maps in the simulation, the first is the "real" map, containing all obstacles and a target; the second is the "internal" map, which starts off empty but is filled as the robot detects obstacles as it moves towards its target (the detection process is simply scanning an area around the robot and adding any tiles in the area to the other map); and the final is a simplified node map with nodes connecting all separate areas with lines illustrating paths between them.

The problem I've run into is that I just can't work out how to detect separated areas - I would like the robot to detect empty areas and use their center points as the nodes for the simplified node map. An illustration of what I am trying to achieve:
Image

Thanks in advance.
-Gopiandcoshow

I have included my project .love file - no pathfinding is currently implemented, only the detection - the robot can be manually controlled with the arrow keys and the internal map can be seen by holding "a".
Attachments
Prototype.love
(49.22 KiB) Downloaded 52 times
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Detection of connected areas in a map

Post by micha »

Detecting connected areas is usually done using a floodfill algorithm. To make this work for you, the individual areas need to be clearly separated. Otherwise, they count as one large area. To get them separated, you can try to increase the boxes (virtually) until they touch. Or you could iterate over all boxes and if two boxes are closer than 2 tiles, then draw a connection between them.

However, I think you don't need this separation at all. Is there any reason, why you want to avoid path finding on the full grid?
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 2 guests