# 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
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Middle School Assistant TeacherCommented:
You could use GDI functions...

Create a Polygon to represent each region via the CreatePolygonRgn() API:
http://www.mentalis.org/apilist/CreatePolygonRgn.shtml

Then you can use the PtInRegion() API to determine if a point is contained by a Region:
http://www.mentalis.org/apilist/PtInRegion.shtml
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Middle School Assistant TeacherCommented:
Don't forget that all GDI calls use PIXELS so convert your coordinates if necessary.
0
Author Commented:
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!
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.