Procedural Road Generation, Unity - dictionary

Im developing 2d isometric game. You driving car on city, thats all.
The issue is generating random maps with connected roads.
I would like to write script - i think i will be able to - but i cant find an idea for alghoritm itself.
Lets say i have 100x100 map, and i would like to build boolean table 1 is road 0 is not road.
As far i have solution that is drawing random number of lines (4-8 for ex) in horizontal and same vertical. But this road map is straight.
Can u share some ideas? Any will help

the question is too broad for a simple answer. theres plenty of ways in various degrees of complexity.
but as tip, consider the problem from a different perspective. sure in the end you want roads, but why are the roads there in the first place?
in your case its a city. a city consists of city blocks wich usually are rectangular. so one way would be to find a way to fill the map with rectangular shapes and consider the edges roads (or only some).
or you could look into triangulation algorithms and triangulate your map with a bunch of random points. then combine some triangles and use those edges as roads.
or even only use a random walk set up so it doesnt turn around completely.
or ...
... seriously though, the options and possible solutions are manifold and dependent on your skill level (as well as how you want to look your city in the end).
dont search for your specific problem, try to adapt some other algorithm for your need. theres plenty of tutorials on random dungeon generation for roguelike games.
also in the end there probably wont be a single generation algorithm giving you the best result, but a combination of many.

Related

Maps API 3 Directions with fuzzy via co-ordinates

I have a number of GPS co-ordinates that describe a route. My intention is to draw a polyline along the route, and then colour segments based on some data I have.
Problem is, the GPS coordinates can occur on the roadside either side of main roads. When using the obvious Directions service solution a lot of "back and forth" occurs as Google tries to get me either side of a split lane road
What I am aiming for is a direct route from A-H passing through every way point. I have considered reverse geocoding the coordinates to a street name and having the directions use the street as a way point, but that picks a specific point on the street that may not be related to the actual route. Single polylines are also not an option as some routes have turns in them.
Is there a way to 'fuzzy' my waypoints so that the directions are happy when passing within a certain radius of the points? If not, has anyone got any other solutions?
Thanks heaps.
Edit: It's also not an option to just not use the middle way points because sometimes the path is not optimal.
Also have tried my own fuzzy coords now, by +- some small value to each consecutive lat/lng pair. Unsurprisingly I ran into OVER_QUERY_LIMIT pretty soon.

Google Maps API V3 -> Utilize MarkerCluster but have the clusters themselves be specific to a drawn polygon/region?

Ok, let me preface this question with the fact that I have created a lot of google maps, but they have been strictly markers and polylines denoting routes and a couple with some handler interaction.
Now I am looking to show basically a map of the world, mostly North America and I want to split this continent into my predefined regions with some lats/lngs that I have. Using these regions I want to draw something like a polygon with a light opacity and different color per region.
I then want to use marker clustering but I want the clusters to be specific to these regions. I have looked around but I haven't found an example like this. I have seen pages that say you can do this but not how you would go about doing this. Again, I am definitely a noob when it comes to drawing polygons and using the marker cluster. I know this question is fairly vague but just looking for an example/idea to start off of, and more so I don't want to write a bunch of code against this specific api and then find out that it is not possible.
Any ideas or suggestions are greatly appreciated....Thanks.
It can be done, but will require a rewrite of the MarkerClusterer (probably will simplify it).
You will need to determine how you are going to represent and load the cluster boundary polygons (KML, GeoJSON, native Google Maps API v3 polygons) and probably use the google.maps.geometry.poly.containsLocation(point:LatLng, polygon:Polygon) instead of LatLngBounds.contains to determine which cluster "owns" a marker.

Create directions on a map based on custom data

So what I'm trying to do is the following:
Have a map (such as Google Maps or questMaps). It doesn't matter at all which API I need to use.
On that map have an overlay on the streets. So say (for example) the street has bad lightning at night, it will be colored red. If it has good lightning it will have a green overlay.
Based on the overlay the map creates a custom route (for example the user only wants to walk on the green/well lit streets).
I have no idea how to accomplish this (especially step 3).
First, you'll have to decide what data you need. How do you categorize certain streets as lit or unlit? What if some parts of a street are well lit and some have no lights? Do you need to know the location of every streetlight in your area? What if lights burn out?
After figuring out what data you need, you need to build your dataset. I'd be VERY surprised if this data already exists, so you will probably need to gather it yourself. Either go around town and take notes, or crowdsource the project, or figure out some other way.
Once you have gathered your data, learn the drawing API of whatever mapping tool you wish to use. They all should have functions in their API for drawing colored lines (for streets) or points (for streetlights) on top of an existing map.
Finally, learn the navigational API of the mapping tool you chose. You're right, this is a hard step. I know Google Maps lets you specify certain waypoints when requesting directions; maybe your app can calculate well-lit waypoints and feed them to Google Maps' Directions service to influence the route it generates.
Good luck!
For custom routing, you need to read up on "Graph Theory". This ignores the geography of the street map, and considers it as a set of junctions (nodes or vertices in the graph theory jargon) connected by edges. You can assign weights to edges - these could be lengths, travel times, ones and zeroes etc. Anything. They can have no relation to the position on the map.
So for your application, you'd assign a large weight to unlit streets, and a small weight to lit streets, then use a standard minimum-weight algorithm to get a route from one node to another.

How to map 2D coordinates from store image to the actual shelves of the store?

We need to build a model of the shop floor in which we can relate pixel coordinates(x, y) from
camera images to the actual objects in the 3D space of the store. The camera images, which will act as sources for generating such a model, suffer from fish-eye distortions. Hence straight lines actually appear as curves in the camera images and the walls appear to meet each other at not exactly right angles.
We are sub-dividing the region into polygons. Each polygon on the image refers to a particular region such as a shelf, display area, checkout counter etc. By mapping the pixels that fall in each polygon, we want to relate it as belonging to the shelf corresponding to that region.
Any ideas how to go about it?
Following is a sample image of the store with some polygons marked:
EDIT:
We are not looking to find out the 3D coordinates, we just need to know which shelf is any polygon mapped to. So if the user clicks on a polygon, we can say he clicked on which shelf.
We are able to manage the above for big polygons like the ones shown in the image, but the shelves away from the camera can be as small as a few pixels so we need some kind of a probabilistic result saying if the user clicked at (x,y) what is the probability that he was trying to click on Shelf-A or what is the probability that he was trying to click on Shelf-B and so on.
Basically, what we are looking for is a probability function which would return the probabilities of click on nearby objects when a small polygon(or a pixel) is clicked on the 2D image.
EDIT2:
One thing which is not apparent from the sample image is that the polygon size could be really small(as small as a few pixels) and polygons in turn could be really close to each other.
Moreover, the use case is that a customer in the store picks a product from one of the shelves. The application user would click on a point in the image from which he thinks the products is picked up. Now since the polygons are so small and so close, the user can only guess the exact point of pickup, so we can only know at best that it could be any one of the 3-4 polygons close to the point of click. So the question is how to calculate probabilities for these 3-4 polygons given the click?
As suggested here distance of the click from the center of polygon and its area could be parameters in calculation of this probability, what I am wondering is if there is algorithm to do so.
We are not looking to find out the 3D coordinates, we just need to know which shelf is any polygon mapped to. So if the user clicks on a polygon, we can say he clicked on which shelf.
I assume you have a mapping from polygon to shelf name. For example, as a list of pairs (polygon, shelf name). You can make it by hand once, if the cameras are fixed and don't move. Then your problem is only finding which polygon does a point belong to.
If you use OpenCV, then you can use its PointPolygonTest function. Otherwise you may write a similar function yourself. See, for example, a Ray casting algorithm. Then look through the list until you find a polygon which the point lies withing.
To further optimize the program you may precalculate polygons' extents. An extents allows you to quickly say when the point is definitely not inside the polygon, and consider only the remaining polygons. But with so few polygons as you have in the image, I would not bother.
Basically, what we are looking for is a probability function which would return the probabilities of click on nearby objects when a small polygon(or a pixel) is clicked on the 2D image.
Just run an experiment, try to click a single highlighted pixel, accumulate some statistics on where the operator does actually clicks. Once you have this, it's easy to predict the number of out-of-object clicks and how far they are likely to be off.
Without such experiment with exactly the same kind of person, the same usage conditions and the same pointing device you are going to use, you cannot really tell how much off the clicks are going to be. I believe that many people are sniper clickers if the mouse is good and they can see the image well. If they are forced to use touch interface or some other pointing device, the precision may be lower.
Few comments
fish eye can be corrected by applying some transformations to the image, see for example this page for some resources including panotools
to get the 3D coordinates only and image from one camera is not enough, additional info is necessary
marking a same point on two images of the same scene from different cameras can give you full 3D info (you do need to know position of each camera relative to each other)
if you are looking for tools to do it, see https://superuser.com/questions/30053/is-there-any-free-open-source-software-that-converts-photos-to-3d-models
EDIT
After update to the question, assuming there already exist a set of polygons and you want to eliminate user errors (or improve precision) you might
try to guess the desired click polygon by calculating distance to centre of weight of polygons close to click
use visual cues (flash the polygon selected and require second click)
collect statistics on errors and for certain polygons require validation
What you want is a space-filling-curce for example a Z-Curce or a Hilbert-Curve. A space-filling-curve sub-divide the plane into smaller tiles and reduce the complexity of 2-Dimensions into 1-Dimension in a way that each tile get's a new order. What might interessting for your problem is that the Hilber-Curve traverse the plane not in binary order but it use a gray code so that every tile is different in 1-Bit from the other tiles. That makes it easy to decide whether the user has clicked this or that object.

Custom Map With Directions

I want to make a map program that gives directions around a campus (residence halls, football field, etc), and within buildings (to offices, cafeteria, etc). Is there anything existing that would help facilitate that?
The alternative seems to be that I would have to create my own map of points and paths around campus and do path-finding for directions.
EDIT: To clarify, I'm wanting to know about how to add spatial awareness to a pathfinding program, in order to generate walking directions for the path. Example: for a hallway full of offices that has two nodes that allow a path to enter the hallway, how do you know if a certain office is on the left from one node and on the right from another?
If I use polygons for the nodes instead of waypoints, I can create a navigation mesh that can be used for pathfinding and directions. For directions and using a rectangle node, if I give the rectangle numbers for its sides from 1 to 4 going clockwise from the top, I know that if I enter side 2 and leave side 1, it's a right hand turn. Or, if I enter side 3 (say, the bottom) and leave side 4, it's a left.
This is pretty hard to answer without knowing what sort of interface you want. Is it supposed to be a Google Maps-type application? Or something simpler? No matter what you're probably going to have to define paths - what things are impassable.
You could do a lot of work and define what's impassable and then use a path-finding algorithm to walk across lawns; but that'd be more work than the simple approach:
Make a map of campus with all the routes greyed out
Define the points and paths in PHP/Perl/Ruby/Python/Coldfusion/ASP.Net/Whatever
Get the Start and Destination from the user
Run Dijkstra's Algorithm
Display the map of campus with overlays highlighting the route segments to light up their path.

Resources