python using 352 619 Geometry point position Exercise 431 sh
python using 3.5.2!!!!!!!!!!!
*6.19 (Geometry: point position) Exercise 4.31 shows how to test whether a point is on the left side of a directed line, on the right, or on the same line. Write the following functions:
def leftOfTheLine(x0, y0, x1, y1, x2, y2):
def onTheSameLine(x0, y0, x1, y1, x2, y2):
def onTheLineSegment(x0, y0, x1, y1, x2, y2):
Write a program that prompts the user to enter the three points for p0, p1, and p2 and displays whether p2 is on the left of the line from p0 to p1, on the right, on the same line, or on the line segment. The sample runs of this program are the same as in Exercise 4.31.
Solution
Here is the code for the first 2 functions:
#!/usr/bin/python
def leftOfTheLine(x0, y0, x1, y1, x2, y2):
d = (x2 - x0) * (y1 - y0) - (y2 - y0) * (x1 - x0)
if d > 0:
return True
def onTheSameLine(x0, y0, x1, y1, x2, y2):
d = (x2 - x0) * (y1 - y0) - (y2 - y0) * (x1 - x0)
if d == 0:
return True
