Note this is using PYTHON. Please don’t write the code out, show me a screenshot
ID: 3592924 • Letter: N
Question
Note this is using PYTHON. Please don’t write the code out, show me a screenshot from python’s IDLE so I can see how you do the format to fully understand... thank you.7. Circle intersection. Write a program that computed the intersection of a circle with a horizontal 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 -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 it the x values of intersection. Add a decision to handle the program from doviding zero if the line is vertical. Formula: x = +/- square root of r^2-y^2 Note this is using PYTHON. Please don’t write the code out, show me a screenshot from python’s IDLE so I can see how you do the format to fully understand... thank you.
7. Circle intersection. Write a program that computed the intersection of a circle with a horizontal 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 -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 it the x values of intersection. Add a decision to handle the program from doviding zero if the line is vertical. Formula: x = +/- square root of r^2-y^2 Note this is using PYTHON. Please don’t write the code out, show me a screenshot from python’s IDLE so I can see how you do the format to fully understand... thank you.
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 -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 it the x values of intersection. Add a decision to handle the program from doviding zero if the line is vertical. Formula: x = +/- square root of r^2-y^2
Explanation / Answer
class Point{ public: float x, y; Point(float px, float py) { x = px; y = py; } Point sub(Point p2) { return Point(x - p2.x, y - p2.y); } Point add(Point p2) { return Point(x + p2.x, y + p2.y); } float distance(Point p2) { return sqrt((x - p2.x)*(x - p2.x) + (y - p2.y)*(y - p2.y)); } Point normal() { float length = sqrt(x*x + y*y); return Point(x/length, y/length); } Point scale(float s) { return Point(x*s, y*s); } }; class Circle { public: float x, y, r, left; Circle(float cx, float cy, float cr) { x = cx; y = cy; r = cr; left = x - r; } pair intersections(Circle c) { Point P0(x, y); Point P1(c.x, c.y); float d, a, h; d = P0.distance(P1); a = (r*r - c.r*c.r + d*d)/(2*d); h = sqrt(r*r - a*a); Point P2 = P1.sub(P0).scale(a/d).add(P0); float x3, y3, x4, y4; x3 = P2.x + h*(P1.y - P0.y)/d; y3 = P2.y - h*(P1.x - P0.x)/d; x4 = P2.x - h*(P1.y - P0.y)/d; y4 = P2.y + h*(P1.x - P0.x)/d; return pair(Point(x3, y3), Point(x4, y4)); } };Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.