# 这个是4.31的代码,一个函数里包含了。在线上,在线左,在线右defjudgePoint(x0, y0, x1, y1, x2, y2):
juMethod =((x1 - x0)*(y2 - y0))-((x2 - x0)*(y1 - y0))if juMethod >0:print("p2 is on the left side of the line from p0 to p1")elif juMethod ==0:print("p2 is on the same line from p0 to p1")elif juMethod <0:print("p2 is on the right side of the line from p0 to p1")
turtle.penup()
turtle.goto(x0, y0)
turtle.dot(6,'red')
turtle.pendown()
turtle.goto(x1, y1)
turtle.dot(6,'red')
turtle.penup()
turtle.goto(x2, y2)
turtle.dot(6,'blue')
turtle.hideturtle()
turtle.done()
judgePoint(34,20,65,95,-50,40)
judgePoint(10,10,50,50,20,20)
judgePoint(34,20,65,95,50,25)
defleftOfTheLine(x0, y0, x1, y1, x2, y2):
juMethod =((x1 - x0)*(y2 - y0))-((x2 - x0)*(y1 - y0))if juMethod >0:print("p2 is on the left side of the line from p0 to p1")
turtle.penup()
turtle.goto(x0, y0)
turtle.dot(6,'red')
turtle.pendown()
turtle.goto(x1, y1)
turtle.dot(6,'red')
turtle.penup()
turtle.goto(x2, y2)
turtle.dot(6,'blue')
turtle.hideturtle()
turtle.done()defonTheSameLine(x0, y0, x1, y1, x2, y2):
juMethod =((x1 - x0)*(y2 - y0))-((x2 - x0)*(y1 - y0))if juMethod ==0:print("p2 is on the same line from p0 to p1")
turtle.penup()
turtle.goto(x0, y0)
turtle.dot(6,'red')
turtle.pendown()
turtle.goto(x1, y1)
turtle.dot(6,'red')
turtle.penup()
turtle.goto(x2, y2)
turtle.dot(6,'blue')
turtle.hideturtle()
turtle.done()defonTheLineSegment(x0, y0, x1, y1, x2, y2):
juMethod =((x1 - x0)*(y2 - y0))-((x2 - x0)*(y1 - y0))if juMethod <0:print("p2 is on the right side of the line from p0 to p1")
turtle.penup()
turtle.goto(x0, y0)
turtle.dot(6,'red')
turtle.pendown()
turtle.goto(x1, y1)
turtle.dot(6,'red')
turtle.penup()
turtle.goto(x2, y2)
turtle.dot(6,'blue')
turtle.hideturtle()
turtle.done()