Results 1 to 8 of 8

Thread: Algorithm...Point in Region??? [Resolved, but read me anyway :)]

  1. #1

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Cool Algorithm...Point in Region??? [Resolved, but read me anyway :)]

    How does the API function...

    Declare Function PtInRegion Lib "gdi32" Alias "PtInRegion" (ByVal hRgn As Long, ByVal x As Long, ByVal y As Long) As Long

    ...work?

    I don't mean "how do I use it?" though, I already know that

    What algorithm is it based on? Does anyone have code for a similar algorithm?
    Last edited by wossname; Dec 10th, 2003 at 06:04 AM.
    I don't live here any more.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    it is actually much simpler than it first sounds, you just need to do the following:
    • from the "point", move in any direction to the edge of the shape (lets say "up")
    • count how many of the borders of the region you cross on the way
    • if the number is even (or 0) you are not inside the shape (as you have gone in & back out.
      if it is an odd number, you are inside it

    (if you arent sure, I would recommend using a piece of paper & drawing a randomly shaped polygon, & check various points)


    in terms of code, you can just check each line of the polygon to see if it crosses the X position of your point, then check if the Y position of the place where it crosses is <= the Y of the point

  3. #3
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    From the MSDN itself...

    INFO: Alternative to PtInRegion() for Hit-Testing:

    http://support.microsoft.com/default...en-us%3B121960

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    If i remember correctly regions are lists of sorted RECT's, and does not contain metainformation about polygons or ellipses, and I guess some version of binary search would take place. Still using regions is not a good idea if you're not really working on device contexts' as they are resource expensive (especially ellipses and polygons)
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Cool, Thanks guys.

    Kedaman, I wasn't planning to use it very heavily in a graphical sense, it's mainly to satisfy my curiosity as I couldn't think how it was done.

    I'll give the line-counting method a try. It should do away with the ned for creating lots of rectangular regions.

    Thanks again!

    AW
    I don't live here any more.

  6. #6

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    I just tried it out on paper...that is SO sexy.
    I don't live here any more.

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    Originally posted by wossname
    I just tried it out on paper...that is SO sexy.



    whatever floats your boat I suppose...


  8. #8

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Hey, babe your looking pleasantly polygonal this evening



    I don't live here any more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width