// constructor for width and length and origin offset
struct Rectangle Rectangle(float base, float height, Point offset)
{
struct Rectangle temp;
temp.itsLowerLeft=offset;
temp.itsLowerRight=makepoint(offset.x+base,offset.y);
temp.itsUpperLeft=makepoint(offset.x,offset.y+height);
temp.itsUpperRight=makepoint(offset.x+base,offset.y+height);
return temp;
}
// get width of rectangle
float getWidth(struct Rectangle a){
return (a.itsLowerRight.x- a.itsLowerLeft.x) ;
}
// get height of rectangle
float getHeight(struct Rectangle a)
{return (a.itsUpperRight.y-a.itsUpperLeft.x);
}
// get area of rectangle
float getArea(struct Rectangle a)
{
return getHeight(a) *getWidth(a);
}
// look for overlap between two rectangles
// bool isOverlap(struct Rectangle a, struct Rectangle b)
bool ispointinRec(struct Point p, struct Rectangle r){
return p.x >= r.itsLowerLeft.x && p.x < r.itsUpperRight.x
&& p.y >= r.itsLowerLeft.y && p.y < r.itsUpperRight.y;
}
int main() {
struct Rectangle a, b, c;
struct Point pt1, pt2, pt3;
float bs = 3;
float height = 6;
pt1 = makepoint(0.0,0.0);
pt2 = makepoint(1.0,1.0);
pt3 = makepoint(1.0,2.0);
a = Rectangle(pt1, pt2);
b = Rectangle(bs, height);
c = Rectangle(bs, height, pt3);
cout << "------------ a ---------- " << endl;
cout << "Width of a: " << getWidth(a) << endl;
cout << "Height of a: " << getHeight(a) << endl;
cout << "Area of a: " << getArea(a) << endl;
cout << "------------ b ---------- " << endl;
cout << "Width of b: " << getWidth(b) << endl;
cout << "Height of b: " << getHeight(b) << endl;
cout << "Area of b: " << getArea(b) << endl;
cout << "------------ c ---------- " << endl;
cout << "Width of c: " << getWidth(c) << endl;
cout << "Height of c: " << getHeight(c) << endl;
cout << "Area of c: " << getArea(c) << endl;
cout << "------------ isOverlap a & b ---------- " << endl;
if (isOverlap(a,b) == true)
cout << "YES " << endl;
else
cout << "NO " << endl;
cout << "------------ isOverlap a & c ---------- " << endl;
if (isOverlap(a,c) == true)
cout << "YES " << endl;
else
cout << "NO " << endl;
cout << "------------ isOverlap b & c ---------- " << endl;
if (isOverlap(b,c) == true)
cout << "YES " << endl;
else
cout << "NO " << endl;
return 0;
}
I think we should finish the overlap function that is before the main function
please help me.I should know the way to do it the final exam is coming soooon
thanks
If the rectangles are oblique then it is a bit complecated. I think I filter out the most cases and yours the last. So it should be look at that some of one line of the first rectangle goes through the lines of the other rectangle. It is a geometry task.