Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!crdgw1!uunet!mcsun!hp4nl!alchemy!ptavoly From: ptavoly@cs.ruu.nl (Peter Tavoly) Newsgroups: comp.sys.amiga.programmer Subject: Re: Clicking on irregular shapes? Message-ID: <1991Apr09.164000.1998@cs.ruu.nl> Date: 9 Apr 91 16:40:00 GMT Organization: Utrecht University, Dept. of Computer Science Lines: 96 This post contains reactions to three other posts in the same thread. 1. umueller@iiic.ethz.ch (Urban Dominik Mueller) writes: >> /\ >> / \ /\ >> / O \ / \ X >> / \/ ___\ >> /_______ / >> \/ >>where you draw the horizontal line from the 'O' to the 'X', now, it intersects >>an odd number of boundaries, yet it is OUTside the shape. Or am I mistaking >>something here? > >Am *I* mistaking *you*? The way I see it, the 'O' is clearly inside, as the >algorithm states. Or are you talking about the 'X'? 'X' must be a point that's >sure to be outside, but 'O' is the point in question. The polygon can be as >complex as you want. You wrote, that you explained it the other way around; I guess that's why I did it that way too :) >> /\ >> / \ / >> / O \ / X >> / \/ >> /_______/ >>Here, an even number of boundaries is crossed. (The second intersection is a >>single line) > >The polygon must be closed for this algorithm to work. To make it closed, >you have to draw a second line over that single line already drawn, there- >fore you get a double interection at that line, so the total number of inter- >sections is odd again -> inside. Yes, that is the problem, what if it is not closed? You are bound to come across one of those at some point. BTW, I was thinking of a bitmap indeed, not a polygon, or maybe an imaginary polygon only, which is not visible but is the internal representation of the boundaries and then a bitmap inside for the graphical stuff. > >BTW I just discovered that I explained the problem with the imaginary line >going through a vertex exactly the wrong way round. Count the intersection >only if it's *no* local maximum or minimun, otherwise don't (or do it twice). >My apologies if that caused problems to anyone. No problem. > | Urban Mueller | / / | Urban Mueller | > | INTERNET:umueller@iiic.ethz.ch | __ / / | Schulhausstr. 83 | > | FIDONET: 2:302/906 (AUGL) | \ \/ / | CH-6312 Steinhausen | > | "Don't tell my employer" | \__/ | SWITZERLAND | 2. nj@magnolia.Berkeley.EDU (Narciso Jaramillo) writes: >In article <1991Apr05.104141.2118@cs.ruu.nl> ptavoly@cs.ruu.nl (Peter Tavoly) writes: [shapes and stuff deleted] > >I just realized that you may be assuming that this test works with raw >bitmaps. In general, it only completely works if you have an internal >representation of your polygons. If you're only working with a bitmap >image, this won't work so well in degenerate cases. It's probably >better to go ahead and represent your polygons internally--a simple >array of line endpoints won't take up much room. Exactly that's what I was thinking. Thank you for the suggestions. >nj 3. dillon@overload.Berkeley.CA.US (Matthew Dillon) writes: > I think the best solution is to simply have a grainy bitmap of the > object and just compare the coordinate against the grainy bitmap (e.g. > a 16x16 bitmap = 32 bytes) > > (for this case) Yes, I think I might be lazy and do this :^) > -Matt -Thomas T. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "Help, I've been attacked by a Prime terminal at 1200 baud!!!" -Thomas T. Did you know that IBM have a secret factory with an infinite number of monkeys? That's how they invented MS-DOS... -ptavoly@praxis.cs.ruu.nl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --