Link to home
Start Free TrialLog in
Avatar of Togno
Togno

asked on

Determine if a point (x,y) is internal or external a region composed by n(3,4,5...) lines.

Hi guys,

I'm writing a small 2D car game in VB. I have problems finding out a good (and FAST) code to determine if the car (x,y) is on or out of the road.
What I've done is divide the road in many regions composed by a number of lines (usually 4 lines), and I set the lines as invisible.
Now I need the code to determine if the car is inside one of the polygons or out of them.

Data:
Region1(line1(x1,x2,y1,y2), line2(x1,x2,y1,y2),  line3(x1,x2,y1,y2), ...)
Region2(line1(x1,x2,y1,y2), line2(x1,x2,y1,y2),  line3(x1,x2,y1,y2), ...)
....
Car(x,y)


If you suggest any faster way to do what I'm looking for feel free, it will be very appreciated. Please if possible post the code.
Thanks
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Don't forget that all GDI calls use PIXELS so convert your coordinates if necessary.
Avatar of Togno
Togno

ASKER

Fantastic!! Exactly what I was looking for.
Not tested in the game yet, but seems perfect, I hope it's fast enough not to slow down the game! I let you know.

I thank you so much!