This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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?
jQuery in Action, 2nd edition
subject: Rectange Problem
Similar Threads
Head First Java problem
Maximum Sum Project!!
need help creating a method for rotate
Finding the color of a pixel
problem in using paint