Skip to main content
gamedev.net
🔒 Locked

intersecting rectangles

Started by MENTAL Feb 21, 2003 at 4:44 AM 0 replies 350+ views
Original Post
MENTAL
MENTAL
okay, a quick one here. does anyone know how to calculate the two points that would continue the perimeter of two intersecting rectangles without using 50 if-then-else statements? There are only two types of possibilities - side intersection and corner intersection.

Side
 ___________               ___________
|         __o_____        |           |_____
|        |  |     |       |                 |
|        |  |     |       |                 |
|        |  |     |       |                 |
|        |__o_____|       |            _____|
|___________|             |___________|

Corner:
        __________               __________
       |          |             |          |
       |          |             |          |
 ______o____      |       ______|          |
|      |    |     |      |                 |
|      |____o_____|      |            _____|
|           |            |           |
|           |            |           |
|___________|            |___________|

the rectangles are actually axis-aligned bounding boxes, but i dont need the height component for this part. they can either be represented using vec3 Origin, Size or vec3 Min, Max. any ideas on calculating the 3d plane those two points make wouldn''t go amiss either cheers
v71
v71
OK, i try to give a solution, first you may notice that only vertical lines intersect horizontals, so you may check if the two vertical lines of the target rectangle are intersected by the horizontal from the fisrt rectangle , if so , compute the intersection point , its simple and fast because lines are always a (1,0) or ( 0,1 ) direction vector, when you compute the intersection points, you can cut the intersected line in two 2 or 1 part, ad thes clipped lines to a list , and go on with the other test, now you need to check for the vertical lines for the first rectangle against the horizontal from the second, i hope it is clear, because my english is getting a little bit rusted, for the second question, maybe you want the outline of this rectangle because they already lies on a plane, maybe you wnat the normal, well , pick 3 points, call one of them origin and create two vectors, they always lies on the same plane in this case, cross product them and you are done.
byez

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.