File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Rectange Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Rectange Problem" Watch "Rectange Problem" New topic

Rectange Problem

ManChun Lam
Ranch Hand

Joined: May 04, 2008
Posts: 32
Assuming I know the 4 coordinates of any rectange. What is the quickest way to check if any 2 rectangles are connected with each other (adjacent)? Thank you.
Charles Lyons
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
Sounds like a homework problem. What's your thinking so far?

Just to clarify, by "adjacent" you mean that two rectangles will touch each other on exactly one side (discounting the possibility of touching vertices but not edges) and do not overlap?

Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
Are you allowed to use java.awt.Rectangle, or are you trying to deal with the geometry from scratch.

Draw each case on paper, and determine how you would test the geometry for that.

Are you using integers or decimals?

Also, it's good to review

Bill Shirley - bshirley -
if (Posts < 30) JavaRanchFAQ);
Joseph Fisher

Joined: Jun 09, 2008
Posts: 5
If you know the coordinates, wouldn't you know what lines fell on what axis? That would tell you which lines connect,right?
I agree. Here's the link:
subject: Rectange Problem
It's not a secret anymore!