Solved

Image map Polygon Algorithm

Posted on 1999-01-22
11
756 Views
Last Modified: 2013-12-25
I'm trying to write the function which tells me whether
an (x,y) point is in a certain polygon?

i already written ones for rectangle & circle but stuck on
the Poligon - the function looks like that:
pointInPolygon(File i_mapFile , double x, double y)
{}
i dont need you to write a code just a way or an algorithm
to find that (x,y) point is in or not the polygon.

a polygon is at least 3 points of lines that are connected togther (0,0)(100,50)(200,30) the first point should be the last and if its not so im adding another connecting point
but thats for another session!

Thanks,
0
Comment
Question by:cs4ez
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 7

Expert Comment

by:Inteqam
ID: 1866798
a simple way is to floodfill the region that contains the point you want with a specific color, and then check the color of a point your are sure it is inside the polygon , if it has the same color you floodfilled , then the point is in the polygon , and vice versa

0
 
LVL 84

Expert Comment

by:ozo
ID: 1866799
or count the number of times a segment of the polygon crosses a ray from the point to infinity
0
 
LVL 7

Expert Comment

by:Inteqam
ID: 1866800
yes ozo , i thought of that , but i found it so difficult , especialy if the polygon is drawn by giving the coordinations of the heads , and also the problems of a point that lies on the line , and also and most important the problems of rounding , which will have a great effect considering that we are using pixels

0
 

Author Comment

by:cs4ez
ID: 1866801
coloring the polygon is a bigger problem!
0
 
LVL 7

Expert Comment

by:Inteqam
ID: 1866802
ok , try ozo solution , it is difficult somehow , but it may help you

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 84

Expert Comment

by:ozo
ID: 1866803
I think the easiest way to deal with boundary ambiguities is to treat the lines as lieing between pixels, rather than on them.
Rounding problems can usually be dealt with by doing everything with integers.
A flood fill would have all the same problems, but would have to deal with them for each pixel in the region.
Still, it may be advantagous to do that once, then use the resulting color map to test points many times.
If you have any difficulty, just ask for furthur help.
0
 

Author Comment

by:cs4ez
ID: 1866804
Please Do Not Attempt to Answer this question - I've Already fount the algorithm i need
in java.awt.Polygon

All answers from now on will be rejected!!!

Thanks ozo & Inteqam for all your efforts

0
 
LVL 1

Accepted Solution

by:
web_crusher earned 100 total points
ID: 1866805
look at java.awt.Polygon
0
 
LVL 1

Expert Comment

by:web_crusher
ID: 1866806
do not forget who told you about it - cs4ez
0
 
LVL 84

Expert Comment

by:ozo
ID: 1866807
the algorithm used by the contains method in java.awt.Polygon class is the counting one
0
 
LVL 7

Expert Comment

by:Inteqam
ID: 1866808
i don't have the java.awt.polygon

can you pass it?

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now