# Difference of Rectangles

5 messages
Open this post in threaded view
|

## Difference of Rectangles

 Consider two rectangles, a and b. The only constraint I will put on them is that neither contains the other. I wish to create a PolygonMorph programmatically consisting of a merge: b with b removed but all of a retained in the case a and b overlap. I think I see my way to how to do this, but if anyone knows of any code I can look at where something like this is already implemented I'd be much obliged. My idea for how to go about this is to use "turtle logic" more or less as follows: Start with the first vertex of a merge: b which is not inside of b. Proceed clockwise along the bounds of a merge: b; if you hit b turn left, if you hit a turn right. But this may be doing things the hard way. -Thanks, Jim
Open this post in threaded view
|

## Re: Difference of Rectangles

 On May 6, 2007, at 16:12 , Jim Rosenberg wrote: > Consider two rectangles, a and b. The only constraint I will put on   > them is that neither contains the other. I wish to create a   > PolygonMorph programmatically consisting of a merge: b with b   > removed but all of a retained in the case a and b overlap. I think   > I see my way to how to do this, but if anyone knows of any code I   > can look at where something like this is already implemented I'd be   > much obliged. > > My idea for how to go about this is to use "turtle logic" more or   > less as follows: Start with the first vertex of a merge: b which is   > not inside of b. Proceed clockwise along the bounds of a merge: b;   > if you hit b turn left, if you hit a turn right. But this may be   > doing things the hard way. Sounds reasonable. There is a polygon clipper in Rome that you could   take a look at. The class is named RomePolygonClipper in package Rome- Reference at         http://squeaksource.com/Rome.htmlMight be simpler if you state the larger problem you need this for. - Bert -
Open this post in threaded view
|

## Re: Difference of Rectangles

 In reply to this post by Jim Rosenberg >Consider two rectangles, a and b. The only constraint I will put on them is that neither contains the other. I wish to create a PolygonMorph programmatically consisting of a merge: b with b removed but all of a retained in the case a and b overlap. I think I see my way to how to do this, but if anyone knows of any code I can look at where something like this is already implemented I'd be much obliged. > >My idea for how to go about this is to use "turtle logic" more or less as follows: Start with the first vertex of a merge: b which is not inside of b. Proceed clockwise along the bounds of a merge: b; if you hit b turn left, if you hit a turn right. But this may be doing things the hard way. > >-Thanks, Jim Hi, Jim - While it does not produce a polygon, you might well find areasOutside: to be a useful first step. I wrote the original version and should probably apologize for not calling it something closer to "difference".         - Dan