1. mathmatical question..
- Posted by Lee woo seob <wslee at HHI.CO.KR> May 29, 1997
- 677 views
Hi everyone! Can anyone give me nice answer over the problem below; --- here goes problem, Assumes the polygon with arbitrary numbers of points is drawn on the pixel-graphics screen, for example; polygon(RED,1,{{100,200},{200,200},......,} Problem is: How can I know whether the mouse pointer is INSIDE the polygon or not, at the time the mouse button is pressed? Bye! from Lee, WooSeob
2. Re: mathmatical question..
- Posted by David Alan Gay <moggie at INTERLOG.COM> May 29, 1997
- 665 views
> Assumes the polygon with arbitrary numbers of points is drawn on the > pixel-graphics screen, for example; > > polygon(RED,1,{{100,200},{200,200},......,} > > Problem is: > How can I know whether the mouse pointer is INSIDE the polygon or not, > at the time the mouse button is pressed? > > Bye! > from Lee, WooSeob It's not even a mathematical problem...it's more like a question of "Is the mouse pointer over an image?" There's two ways of attacking this. One way is to use get_pixel() using the returned mouse x and y co-ordinates to obtain the pixel colour of where the mouse pointer is at. In the case of your polygon above, you know you are over the polygon if the colour RED is returned. Admittedly. it's not good for a polygon with mulitple or shared colours, but it works if the polygon is a complex shape. Another way is to make a sequence representing a map of what space the polygon occupies, and then search it using find() with the x and y mouse pointer co-ordinates as the search argument. If you get a hit, you know you are over the shape. This is much more preferable if the icon you are trying to make clickable is multi-coloured. Hope this helps David Gay http://www.digital-liquid.com/abgte "A Beginner's Guide To Euphoria"
3. Re: mathmatical question..
- Posted by Lucius L Hilley III <luciuslhilleyiii at JUNO.COM> May 29, 1997
- 690 views
Jiri's Reply has SOME merit mathmatically. However it is only 50% accurate. EXAMPLE ________ | _ | | / | | |/ | | . |____| /|\ | [point] If you take this polygon. You click to where his check comes exactly across the point. This would cause an odd count and still be inside the polygon. The easiest way is David Gay's suggestion. Next!!! to do it mathmatically you would have break the polygon into triangles. Then you could use Jiri's idea accurately. You would check each triangle as a seperate polygon. If it is within or on any of the triangles thin it is within or on the polygon. Triangled view ________ | /| /| | / | / | |/ | / | |/___| --Lucius Lamar Hilley III -- E-mail at luciuslhilleyiii at juno.com -- I support transferring of files less than 60K. -- I can Decode both UU and Base64 format.
4. Re: mathmatical question..
- Posted by Lucius L Hilley III <luciuslhilleyiii at JUNO.COM> May 29, 1997
- 711 views
Hello again! Just had another thought. Do as Jiri said go from click point in one direction until you hit a polygon line or reach the screen edge. Now go from the click point in the opposite direction until a polygon line or reach the screen edge. If first hit line & second hit line then You are in the polygon. else You are not. end if --Lucius Lamar Hilley III -- E-mail at luciuslhilleyiii at juno.com -- I support transferring of files less than 60K. -- I can Decode both UU and Base64 format.
5. Re: mathmatical question..
- Posted by Michael Bolin <michaeltom at GEOCITIES.COM> May 29, 1997
- 662 views
- Last edited May 30, 1997
> Jiri's Reply has SOME merit mathmatically. > However it is only 50% accurate. > > EXAMPLE > > ________ > | _ | > | / | | > |/ | | > . |____| > /|\ > | > [point] > > If you take this polygon. > You click to where his check comes exactly > across the point. This would cause an odd count > and still be inside the polygon. No, in the case of ANY closed polygon, drawing a line from a point and counting the number of intersections will ALWAYS work. When counting the number of intersections mathematically, lines that lie straight across another do not count as intersection points. It's just a simple matter of topology. This system must ALWAYS work. Michael Bolin
6. Re: mathmatical question..
- Posted by Michael Bolin <michaeltom at GEOCITIES.COM> May 30, 1997
- 645 views
- Last edited May 31, 1997
> Hi everyone! > > Can anyone give me nice answer over the problem below; > > --- here goes problem, > > Assumes the polygon with arbitrary numbers of points is drawn on the > pixel-graphics screen, for example; > > polygon(RED,1,{{100,200},{200,200},......,} > > Problem is: > How can I know whether the mouse pointer is INSIDE the polygon or not, > at the time the mouse button is pressed? Here's a function that will do this. It computes the number of line intersections mathematically, and will work for any polygon. Regards, Michael Bolin --------------------------------------------------- function inside(sequence point,sequence points) atom x1,y1,x2,y2,x,y,min,max integer intersections intersections=0 x=point[1] y=point[2] x2=points[length(points)][1] y2=points[length(points)][2] for t=1 to length(points) do point=points[t] x1=point[1] y1=point[2] if y1!=y2 then min=y1 max=y2 if y2<y1 then min=y2 max=y1 else min=y1 max=y2 end if if y>min and y<=max then if x<=x1+(x2-x1)/(y2-y1)*(y-y1) then intersections=intersections+1 end if end if end if x2=x1 y2=y1 end for return remainder(intersections,2) end function ------------------------------------