Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Rectange Problem

 
ManChun Lam
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you know the coordinates, wouldn't you know what lines fell on what axis? That would tell you which lines connect,right?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic