Win a copy of Functional Reactive Programming this week in the Other Languages forum!

# Rectange Problem

ManChun Lam
Ranch Hand
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
Author
Ranch Hand
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?

Bill Shirley
Ranch Hand
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 faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch

Joseph Fisher
Greenhorn
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?