c# - Relation of two squares -
my homework make program draws 2 squares, , determines if cross, touch, inside of 1 another, or neither.
i use 2 point system: first top-left, other bottom-right. then, draw lines between them.
can you, please, tell me simple algorithm determines of these 4 cases happen?
crossing:
┌────┐ │ ┌──────────┐ │ │ │ │ └──│─┘ │ └──────────┘
touching:
┌────┐ │ │──────────┐ │ │ │ └────┘ │ └──────────┘
inside of 1 another:
┌──────────┐ │ ┌────┐ │ │ └────┘ │ └──────────┘
neither:
┌────┐ │ │ ┌──────────┐ │ │ │ │ └────┘ │ │ └──────────┘
well won't put code you, because it's not language specific problem, , because it's do. here's pointers:
- you have 2 intervals on x axis, , 2 on y axis
- it's known how determine if 2 intervals overlap. can determine whether 1 interval entirely inside other.
- for squares overlap, there's simple condition need test for. think of is.
- bonus: can work out overlap area well.
Comments
Post a Comment