|
-
Oct 30th, 2001, 01:29 PM
#1
Thread Starter
Fanatic Member
PolyGon in PolyGon
Can anyone tell me how to check if one 2D polygon is within another. This function needs to be as quick as possible so preferably C++.
Thanks
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]
-
Oct 30th, 2001, 04:42 PM
#2
Lively Member
Don't know if it is of any help..but give it a look.
http://astronomy.swin.edu.au/pbourke...ry/insidepoly/
Marriage - is not a word, but a sentence.
-
Oct 31st, 2001, 04:20 AM
#3
Thread Starter
Fanatic Member
Thanks for the reply - but I need to check for an entire polygon inside another polygon. I can't check each point to see if it is inside or out of the other polygon - because while all the points may be inside - a line connecting 2 points may fall outside.
Any other sites???
Thanks
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]
-
Oct 31st, 2001, 05:38 AM
#4
transcendental analytic
A line is totally inside a polygon if doesn't cross any of it's sides, and a line to one of it's end points from an arbitary point outside (preferably vertical) crosses an odd amount of the polygons sides. A whole polygon is inside another if none of it's sides crosses any of the other polygon's and one of the corners can be verified to be inside the polygon using the method I mentioned
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.
-
Oct 31st, 2001, 06:35 AM
#5
Thread Starter
Fanatic Member
Cheers - any sample code?
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]
-
Oct 31st, 2001, 07:03 AM
#6
transcendental analytic
Something like this:
bool is=false;//inside/intersection
for (lineiterator i2=plg2.first;i2<pl2.last;i2++){
is^=
((
(plg1.first.first.x>i2.first.first.x
)^(
plg1.first.last.x>i2.first.last.x
))&&(
i2.first.first.y+(i2.first.last.y-i2.first.first.y)/(plg1.first.first.x-i2.first.first.x)*(i2.first.last.x-i2.first.first.x)
)
}
if (!is) return false;
for (lineiterator i1=plg1.first;i1<pl1.last;i1++)
for (i2=plg2.first;i2<pl2.last;i2++)
if(is=i1.iscross(i2)) break;
return is;
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.
-
Oct 31st, 2001, 07:30 AM
#7
Thread Starter
Fanatic Member
Thanks - I am using Borland so I don't have that lineiterator object - however I'll work it out.
Thanks
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]
-
Oct 31st, 2001, 08:19 AM
#8
transcendental analytic
lineiterator doesn't come with as a component in any library, i just invented it for the use of acting as a line and as a iterator in the polygon, the iterator would point to a specific corner in the polygon (and iterate to next corner with ++ operator) while the line part of the interface would provide that corner point first and the next corner point last as two end points of a line.
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.
-
Oct 31st, 2001, 10:14 AM
#9
Thread Starter
Fanatic Member
Thanks - I think I have the bones of a C++ function that will do it.
Just on another point - if I wanted to place a grid over a polygon and then I just want returned the grid sections that are entirely inside the polygon - do you know how that would work??
Do you know what I mean?
Thanks
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]
-
Nov 1st, 2001, 11:34 AM
#10
transcendental analytic
Yep, it's called Bresenham algoritm
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.
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
|