Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 7 - Objects and Classes - Programming Exercises - Page 239: 7.9

Answer

code

Work Step by Step

# 7.9 (Geometry: intersection) Suppose two line segments intersect. The two endpoints # for the first line segment are (x1, y1) and (x2, y2) and for the second line segment # are (x3, y3) and (x4, y4). Write a program that prompts the user to enter these # four endpoints and displays the intersecting point. (Hint: Use the # LinearEquation class from Exercise 7.7.) from CH7.LinearEquation import LinearEquation x1, y1, x2, y2 = eval(input("Enter the endpoints of the first line segment: ")) x3, y3, x4, y4 = eval(input("Enter the endpoints of the second line segment: ")) a = y1 - y2 b = -x1 + x2 c = y3 - y4 d = -x3 + x4 e = -y1 * (x1 - x2) + (y1 - y2) * x1 f = -y3 * (x3 - x4) + (y3 - y4) * x3 eq = LinearEquation(a, b, c, d, e, f) print("The intersecting point is: (", eq.getX(), ",", eq.getY(), ")")
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.