Generate obstacles within boundry

Basically I am working on racing game. For that I have used multiple fixed path images to draw path for car.
Following image represent one of the demo of that path.

30972-resized_cave.png

My target is to generate enemy cars within this type of paths. In this image black portion is my road so within that I have to spawn enemy cars. At present I can’t able to figure out how to spawn car within that area because I have other path also with some other patten in those.

I need some help in spawning cars.

even-odd rule algorithm will be helpful if you want to raycast a position. Point in polygon - Wikipedia

Personally, I don’t really like raycasting and is hard to implement for a random spawn position; usually it would be used for checking if an already predetermined point is inside of a polygon. Here is what I would do:

If the polygon is convex then one can consider the polygon as a “path” from the first vertex. A point is on the interior of this polygons if it is always on the same side of all the line segments making up the path.
Given a line segment between P0 (x0,y0) and P1 (x1,y1), another point P (x,y) has the following relationship to the line segment. Compute (y - y0) (x1 - x0) - (x - x0) (y1 - y0)
if it is less than 0 then P is to the right of the line segment, if greater than 0 it is to the left, if equal to 0 then it lies on the line segment.
-.net - C# Point in polygon - Stack Overflow

A simple google really goes quiet a long way. The code provided at the link should be helpful, but if you are unfamiliar with .NET programming I could convert it into ‘unity code’ for you.