Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

7. Circle Intersection. Write a program that computes the intersection of a circ

ID: 3592872 • Letter: 7

Question

7. Circle Intersection. Write a program that computes the intersection of a circle with a hori- zontal line and displays the information textually and graphically Input: Radius of the circle and the y-intercept of the line. Output: Draw a circle centered at (0,0) with the given radius in a window with coordinates running from -10,-10 to 10,10. Draw a horizontal line across the window with the given y-intercept. Draw the two points of intersection in red. Print out the r values of the points of intersection.

Explanation / Answer

#include <bits/stdc++.h>

using namespace std;

int circle(int x1, int y1, int x2, int y2,

           int r1, int r2)

{

    int distSq = (x1 - x2) * (x1 - x2) +

                 (y1 - y2) * (y1 - y2);

    int radSumSq = (r1 + r2) * (r1 + r2);

    if (distSq == radSumSq)

        return 1;

    else if (distSq > radSumSq)

        return -1;

    else

        return 0;

}

// Driver code

int main()

{

    int x1 = -10, y1 = 8;

    int x2 = 14, y2 = -24;

    int r1 = 30, r2 = 10;

    int t = circle(x1, y1, x2, y2, r1, r2);

    if (t == 1)

        cout << "Circle touch to each other.";

    else if (t < 0)

        cout << "Circle not touch to each other.";

    else

        cout << "Circle intersect to each other.";

    return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote