Question: Need help finishing a CSC190 project The Task: Find the Largest Circle Contained by Overlapping Rectangles An upright rectangle can be represented by two diagonal

Need help finishing a CSC190 project

The Task:

Find the Largest Circle Contained by Overlapping Rectangles

An upright rectangle can be represented by two diagonal points, say p1 = (p1x, p1y)

and p2 = (p2x,p2y) A circle can be represented by its center point and radius, say (cx, cy)

and r.

Write a Java program that asks the user to input the points representing two up-right rectangles r1 and

r2 and finds the largest circle c that can be contained in both rectangles, where (cx, cy) is the center

of c and r the radius of c

Assume the two rectangles overlap and have sides parallel to the x and y axis. To be contained in the

rectangles, the circle can touch the sides of the rectangles, but the circles edge may not extend past the

sides of either rectangle.

Need help finishing a CSC190 project The Task: Find the Largest Circle 

What I need help finishing

//declare points //given by user double p1x, p2x, p3x, p4x; double p1y, p2y, p3y, p4y; //tree type method that gets the values double xs1, xs2, xs3, xs4, ys1, ys2, ys3, ys4; double xl1, xl2, xl3, xl4, yl1, yl2, yl3, yl4; //x and y specific points to use for circle double xp1, xp2, xp3, xp4, yp1, yp2, yp3, yp4; double xMidPoint, yMidPoint; double xMaxDis, yMaxDis;

//collect user input Scanner input = new Scanner(System.in); System.out.println("input p1x"); //point one information p1x = input.nextDouble(); System.out.println("input p1y"); p1y = input.nextDouble(); //point two info System.out.println("input p2x"); p2x = input.nextDouble(); System.out.println("input p2y"); p2y = input.nextDouble(); //point three info System.out.println("input p3x"); p3x = input.nextDouble(); System.out.println("input p3y"); p3y = input.nextDouble(); //point 4 info System.out.println("input p4x"); p4x = input.nextDouble(); System.out.println("input p4y"); p4y = input.nextDouble(); //find positions on an axis xs1 = Math.min(p1x, p2x); xs2 = Math.min(p3x, p4x); xs3 = Math.min(xs1, xs2); //smallest of all smallest points (1) xs4 = Math.max(xs1, xs2); //largest of all smallest points (3) xl1 = Math.max(p1x, p2x); xl2 = Math.max(p3x, p4x); xl3 = Math.max(xl1, xl2); //Largest of all points (4) xl4 = Math.min(xl1, xl2); //smallest of all points (2) //to store x points and clean up to make it more readable xp1 = xs3; xp2 = xl4; xp3 = xs4; xp4 = xl3; // math for midpoint xMidPoint = xp2+xp3/2; //Max distance between points xMaxDis = Math.abs(xp3-xp2); System.out.println(xMaxDis); /* (0_0) /|\ | | / \ */ /* the smallest of all four points is first from axis; the largest of the smaller points has to be the 3rd line from axis; the smallest of the larger two points is the 2nd line from axis; the largest of all four points is obviously the farthest point from axis */ //take what we know from x and use on y ys1 = Math.min(p1y, p2y); ys2 = Math.min(p3y, p4y); ys3 = Math.min(ys1, ys2); //smallest of all smallest points (1) ys4 = Math.max(ys1, ys2); //largest of all smallest points (3) yl1 = Math.max(p1y, p2y); yl2 = Math.max(p3y, p4y); yl3 = Math.max(yl1, yl2); //Largest of all points (4) yl4 = Math.min(yl1, yl2); //smallest of all points (2) //to store x points and clean up to make it more readable yp1 = ys3; yp2 = yl4; yp3 = ys4; yp4 = yl3;

// math for midpoint yMidPoint = yp2+yp3/2; //Max distance y between points yMaxDis = Math.abs(yp3-yp2); // math for x midpoint xMidPoint = xp2+xp3/2; //Max distance between x points xMaxDis = Math.abs(xp3-xp2); System.out.println(xMaxDis); //output the given value we learned to the user System.out.print("A circle with points: ("+p1x+","+p1y+"), " + "("+p2x+","+p2y+"), ("+p3x+","+p3y+"), ("+p4x+","+p4y+") will have " + "a circle with a midpoint of: ("+xMidPoint+","+yMidPoint+") and " + "the max distance between the intersecting rectangle points: ("+ xMaxDis+","+yMaxDis+")");

Some sample runs for testing

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!