home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / programm / 2524 < prev    next >
Encoding:
Text File  |  1992-08-29  |  2.8 KB  |  67 lines

  1. Newsgroups: comp.programming
  2. Path: sparky!uunet!s5!is1.is.morgan.com!is.morgan.com!berlin
  3. From: berlin@is.morgan.com (Alexander Berlin)
  4. Subject: Re: How to decide if a point is inside a polygon?
  5. Message-ID: <1992Aug28.134203@is.morgan.com>
  6. Sender: news@is.morgan.com
  7. Nntp-Posting-Host: chico
  8. Organization: Morgan Stanley - IS
  9. References: <7121@bigbird.hri.com.hri.com> <schnitzi.714934670@eola.cs.ucf.edu> <1992Aug27.153902@is.morgan.com> <schnitzi.715017774@eola.cs.ucf.edu>
  10. Date: Fri, 28 Aug 1992 17:42:03 GMT
  11. Lines: 54
  12.  
  13. In article <schnitzi.715017774@eola.cs.ucf.edu>, schnitzi@cs.ucf.edu (Mark Schnitzius) writes:
  14. |> berlin@is.morgan.com (Alexander Berlin) writes:
  15. |> 
  16. |> >When drawind the line in any direction, you want to avoid
  17. |> >crossing corners of the polygon. So, make sure no one of the given points
  18. |> >(that make polygon) belongs to the line.
  19. |> 
  20. |> >        A           B
  21. |> >        .___________.
  22. |> >         \         /
  23. |> >          \  Y.   /
  24. |> >           \  |  /
  25. |> >    X       \ | /
  26. |> >    .________\|/___________________
  27. |> >              |
  28. |> >              | C
  29. |> >              |
  30. |> 
  31. |> >In the above example X is outside triangle ABC, Y is inside it. Their lines
  32. |> >exactly the same crossings whith the edge. So instead of coming up with
  33. |> >additional complicated rules just make sure you don't hit the corners. 
  34. |> 
  35. |> Well, one solution to this problem is this: consider each vertice of the
  36. |> polygon as belonging to only _one_ of the line segments it is connected to.
  37. |> So in the above example,  only consider point C to be on the line segment
  38. |> BC and not on AC.  Then if the line you're drawing goes through point C,
  39. |> it is only considered to have gone through line segment BC and not AC.
  40. |> This simple fix should clear up any problems.
  41.  
  42. No, it doesn't. I didn't say that the line drawn from point X has one or two
  43. crossings. My point is that X-line and Y-line have the same number of crossings
  44. (be it 1 or 2) while X is outside and Y is inside. The fix you suggest doesn't
  45. distinguish X- and Y- cases in my example.
  46. The rule that would work is to check if AC and CB segments are on the same 
  47. side of the line (2 or 0 crossings, case X) or on the different sides 
  48. (1 crossing, case Y). But I think it is much better to just avoid these
  49. confusing cases. It can be even more complex if a direction you select for
  50. the line makes it co-linear with one of the segments. Something like this:
  51.  
  52.              B                 C
  53.       X ._______________________________________________________
  54.             /                  \
  55.            /                    \
  56.           /                      \
  57.          /________________________\
  58.         A                          D
  59.  
  60. |> 
  61. |> Mark Schnitzius
  62. |> schnitzi@eola.cs.ucf.edu
  63. |> University of Central Florida
  64. ---
  65. Alex Berlin                     
  66. berlin@is.morgan.com
  67.