|
-
Aug 24th, 2001, 11:11 AM
#1
Thread Starter
Lively Member
-
Aug 24th, 2001, 01:49 PM
#2
transcendental analytic
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.
-
Aug 25th, 2001, 07:50 AM
#3
transcendental analytic
Choose a point outside the polygon, easiest would be say leftmost vertex -1 or if you are sure for instance that the polygon won't be located in origo, put it there for ease of calculations. A straight line (vertical or horizontal) would probably be even better (since this algoritm requires you calculate line intersections)
for a polygon convex polygon, there will be 1 intersection if the point is inside, 0 or 2 if not. You do this by testing each line in the polygon if it intersects with the line, this would probably be fastest if the line is vertical or horizontal
for a concave polygon there will be odd amount of intersection if the point is inside, odd if not.
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.
-
Aug 26th, 2001, 12:25 AM
#4
Fanatic Member
If you weren't really concerned about speed (since it seems like you're determining this for something that's just for information and not speed purposes), you could take your points and create a region from them using CreatePolygonRgn(), and then test a given point by using PtInRgn() and giving it the handle to the region you just created. If your points are just x,y values this would be pretty easy to do. If the regions are complex though, what Kedaman mentioned would be better since it needs only the points of the polygon. I remembered seeing that before, so I went looking and I found it. The article id is Q121960 in MSDN, and titled "Alternative to PtInRegion() for Hit-Testing."
I'm baaaack...
VB5 Professional Edition, VC++ 6
Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se
I feel special because I finally figured out how to loop midis: Post link
I'm a fanatic too 
-
Aug 26th, 2001, 03:19 AM
#5
transcendental analytic
PtinRegion will just eat up resources for you The regions might either get inprecise or huge bastards if you don't keep them in reasonable scale
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.
-
Aug 27th, 2001, 08:03 AM
#6
Fanatic Member
Here is a C function to determine if a point lies within a polygon:
Code:
c=0;
for (i = 0, j = nbpol-1; i < nbpol; j = i++) {
if ((((tY[i]<=Y) && (Y<tY[j])) || ((tY[j]<=Y) && (Y<tY[i]))) &&
(X < (tX[j] - tX[i]) * (Y - tY[i]) / (tY[j] - tY[i]) + tX[i]))
c = !c;
}
where tX and tY contain the points of the polygon, nbpol is the number of points, X and Y are the point.
if c is true the point is within.
Rob
My secretary hopes that I will pay her, her landlord hopes that she will produce some rent, the Electricity Board hopes that he will settle their bill, and so on. I find it a wonderfully optimistic way of life. [Dirk Gently]
-
Aug 28th, 2001, 03:32 AM
#7
Thread Starter
Lively Member
Thanks guys for all your replies, much appreciated, I'll start playing and see how I get on
cheers
john
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
|