Overlapping rectangles

Overlapping rectangles

Post by James W. Clar » Sat, 17 Aug 1996 04:00:00



In C, I'm writing a program in which I need to draw some 3d
representations of rectangles.  Initially, I've been just throwing
wireframes down, but it has occured to me that after a certain
number of these, the drawing becomes to complex to pick out the
individual rectangles... (In fact they're constructing rectangular
prisms).  They are rectangles of varying size, and are all parallel
to one of the xy,xz,yz planes.

So I've decided to fill the rectangles, so that you can't see the ones
behind it.  So I thought I'd just sort them by depth and draw them
in order, rather than try to draw only visible sections, and so forth.
So my question:

What's a good way to determine if a rectangle is overlapping another,
and which one is closer?  I don't expect these to be too complicated,
but I need some way to determine the order in which I should draw
the rectangles.

----------------------------------------------- James W. Clark

 
 
 

Overlapping rectangles

Post by Matt Setze » Sun, 18 Aug 1996 04:00:00



Quote:> What's a good way to determine if a rectangle is overlapping another,
> and which one is closer?  I don't expect these to be too complicated,
> but I need some way to determine the order in which I should draw
> the rectangles.

        The following works for non-degenerate axis aligned rectangles :
( non degenerate means the rectangle has a positive area, axis aligned
means the sides of the rectange are aligned with the principle axis )

struct Rect
{
        int llx, lly;
        int urx, ury;

Quote:};

//  Returns true if rectangles overlap, false if they do not.
bool RectanglesOverlap( const Rect &r0, const Rect &r1 )
{
        //  Check to see if they overlap in x.
        if ( r0.llx > r1.urx ||
                r0.urx < r1.llx )
                return false;

        //  Check to see if they overlap in y.
        if ( r0.lly > r1.ury ||
                r0.ury < r1.lly )
                return false;

        //  If we get here, they overlap.
        return true;

Quote:}

        Obviously, for a 3D axis-aligned cube, you'd need one more test
in z.  As for determining which is closer, assuming a left-handed
coordinate system with positive x to the right, positive y up, and
positive z into the screen, the rectangle with the smaller z value is
closer.



 
 
 

Overlapping rectangles

Post by James W. Clar » Sun, 18 Aug 1996 04:00:00



on Sat, 17 Aug 1996 11:15:07 -0700

  Ok, that's not what I need to do.

  I'm drawing individual rectangles which are at various sizes
and orientations.  They will never 'physically' overlap, in that
they never intersect.  However, I'm drawing them from an arbitrary
angle, and I'd like to order them such that when they are drawn,
they erase parts of rectangles 'behind' them.

  So, the reason I can't just check for x/y/z overlap individually
is because that doesn't necessarily mean they overlap in the view,
AND the reason I can't use only depth values to determine drawing
order is because they have 4 different depth values, and if rectangle
A is closer than rectangle B to the view origin, then all 4 of A's
points are closer than AT LEAST ONE of B's points, but that oesn't
necessarily mean that it is closer.  What I mean to say, is that
comparison of the z values of the points (or even an average of
them) is insufficient to determine whether one rectangle should be
drawn before or after another.  I need another method.

  So, to clarify, I'm not talking about rectangular prisms... I mean
planar rectangles in 3 dimensions.  And when I said they were parallel
to one of the xy/xz/yz planes, it doesn't affect their angles with
respect to the view, which will be moving around.

Thanks anyway, though. :)


 
 
 

1. Overlapping rectangles -- HELP

I thought this would be trivial problem, but...

If I have the 4 vertices of two rectangles, is there a quick and easy way
to tell if they overlap.  I don't even need the overlapping region!

All I've thoght of so far is brute force checing several cases.  
eg.  one in other, other in one, one with vertices in other, other with
verticies in one, one with line through other, other with line through
one...  I must be missing the boat big time here!

Any help would be GREATLY appreciated!

Thanks,
-Gary

2. text tool problem

3. Merging unit sqaures into non-overlapping rectangles

4. Newbie Level Question - Can someone explain what you're doing when you create and modify Channels?

5. Polygon from overlapping Rectangles?

6. Computing a set overlapping rectangles

7. Overlapping rectangles: how to determine?

8. Q: Outline of overlapping rectangles

9. Overlapping rectangles

10. What is a simple algorithm for creating non-overlapping rectangles?

11. Checking rectangle overlap in a plane