Re: Testing Intersection with A Rectangle(2D) w/No Area

From: Fred L. Kleinschmidt (fred.l.kleinschmidt_at_nospam_boeing.com)
Date: 02/18/04


Date: Wed, 18 Feb 2004 17:21:39 GMT


Aaron Davies wrote:
>
> How do I test a rectangle for intersection with another rectangle which has
> no area, ie where the y1 and y2 co-ords are the same? All the intersect
> methods from awt.geom.Rectangle2D.* and awt.geom.Area seem to test for
> intersection with the interior of the rectangle, but that always returns
> false for a degenerate rect which is equivalent to a line. Do I have to
> create that equivalent line and test intersectsLine, or is there a better
> way?

      Rectangle r = new Rectangle( 1,0,10,10);
      Rectangle s = new Rectangle( 0, 5, 11, 0);
      if ( r.intersects(s) ) {
         System.out.println( "r intersects s");
      }
      if ( s.intersects(r) ) {
         System.out.println( "s intersects r");
      }
      Rectangle q = r.intersection(s);
      System.out.println( "intersection: "+q);

When this is executed, it verifies that r and s intersect, regardless of
whether you use r.intersects(s) or s.intersects(r). And s is a
degenerate rectangle with no height. Are you sure your rectangles
actually intersect?

-- 
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Common User Interface Services
M/S 2R-94  (206)544-5225


Relevant Pages

  • Re: Polymorphism sucks [Was: Paradigms which way to go?]
    ... > intersection when I can return a rectangle? ... Well, depending on the requirements, it might be simpler - for example, if ... wether and how to use an implementation technique like OO. ...
    (comp.object)
  • Re: Intersecting Polygons
    ... I should have asked about the intersection of 2 POLYGONS, ... The polygons can have 3 or more points/sides, ... > Hi Matt: ... > places the coordinates of the intersection rectangle into the destination ...
    (microsoft.public.vb.general.discussion)
  • Re: Calculating the area of intersection of ellipse and a rectangle
    ... Calculating the area of intersection of an ellipse and a rectangle ... may I ask you if anybody knows about an efficient method or may be ...
    (comp.soft-sys.matlab)
  • Re: Intersecting Polygons
    ... don't use polygons much so I can't help you out there. ... I should have asked about the intersection of 2 POLYGONS, ... >> places the coordinates of the intersection rectangle into the destination ... >> Doug. ...
    (microsoft.public.vb.general.discussion)
  • Testing Intersection with A Rectangle(2D) w/No Area
    ... How do I test a rectangle for intersection with another rectangle which has ... ie where the y1 and y2 co-ords are the same? ... false for a degenerate rect which is equivalent to a line. ...
    (comp.lang.java.gui)