wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Rectange Problem" Watch "Rectange Problem" New topic
Author

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
Author
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 faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch


Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
Joseph Fisher
Greenhorn

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?
 
It is sorta covered in the JavaRanch Style Guide.
 
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