(Geometry: point position) Exercise 4.31 shows how to test whether a point is onthe left side of a directed line, on the right, or on the same line. Write the follow-ing functions:
# Return true if point (x2,y2) is on the left side of the#directed line from (xo, yo) to (xi,y1)
def leftOfTheLine(xo,yo,xi,y1,x2,y2):
# Return true if point (x2,y2) is on the same#line from (xo, yo) to (x1,y1)
def leftOfTheLine(xo,yo,xi,y1,x2,y2):
# Return true if point (x2,y2) is on the same#line from (xo, yo) to (x1,y1)
def onTheLineSegment(xo,yo,x1,y1,x2,y2) :
def leftOfTheLine(x0,y0,x1,y1,x2,y2):
k=(y1-y0)/(x1-x0);
y=k*(x2-x0)+y0;
if y2>y:
print("(%d,%d)在直线的左侧"%(x2,y2));
elif y2<y:
print("(%d,%d)在直线的右侧"%(x2,y2));
else:
print("(%d,%d)在直线上"%(x2,y2));
x0,y0=map(int,input().split())
x1,y1=map(int,input().split())
x2,y2=map(int,input().split())
leftOfTheLine(x0,y0,x1,y1,x2,y2);
1190

被折叠的 条评论
为什么被折叠?



