|
-
Dec 9th, 2003, 03:45 AM
#1
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.
-
Dec 9th, 2003, 05:31 AM
#2
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
-
Dec 9th, 2003, 10:42 AM
#3
So Unbanned
From the MSDN itself...
INFO: Alternative to PtInRegion() for Hit-Testing:
http://support.microsoft.com/default...en-us%3B121960
-
Dec 9th, 2003, 02:14 PM
#4
transcendental analytic
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.
-
Dec 10th, 2003, 05:43 AM
#5
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.
-
Dec 10th, 2003, 06:03 AM
#6
I just tried it out on paper...that is SO sexy.
I don't live here any more.
-
Dec 11th, 2003, 04:47 AM
#7
-
Dec 11th, 2003, 03:03 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|