CS19002 Programming and Data Structures Laboratory Spring 2010, Section 5

Assignment 0

A rectangle with sides parallel to the X- and Y-axes is specified by four real numbers a, b, c, and d. Assume that a <= c and b <= d. The four corners of the rectangle are (a,b) [bottom left], (c,b) [bottom right], (a,d) [top left], and (c,d) [top right].

Read the values a1, b1, c1, and d1 from the user for a rectangle R1. Subsequently, read the values a2, b2, c2, and d2 for another rectangle R2. Your task is to determine whether the two rectangles R1 and R2 intersect.

To solve this problem, it suffices to check whether both the following conditions are satisfied:

Two real intervals I = [s,t] and J = [u,v] operlap if and only if I starts before J ends and J starts before I ends, that is, if and only if s <= v and u <= t.

Report the output of your program for the following four runs.

   a1,  b1,  c1,  d1        a2,  b2,  c2, d2
    1,   2,   3,   4         2,   3,   4,  5
    1,   2,   3,   4         3,   4,   5,  6
    1,   2,   3,   4         4,   5,   6,  7
    1,   2,   3,   4       1.5,   5, 2.5,  6

Lab Home Submission Site My Home