总结:数学是个好东西,可惜我没有
代码,不带数学的方法,需要判断分母为0问题
def fun1(points):#没写完,还要判断分母为0情况#把三个点拿出来p1 = points[0]p2 = points[1]p3 = points[2]if (p2[0] - p1[0])!=0:d1 = (p2[1] - p1[1]) / (p2[0] - p1[0])else:#1,2已经在一条直线上了,看三if (p3[0] - p2[0])!=0:d3 = (p3[1] - p2[1]) / (p3[0] - p2[0])else:return Falseif (p3[0] - p1[0])!=0:d2 = (p3[1] - p1[1]) / (p3[0] - p1[0])if (p3[0] - p2[0])!=0:d3 = (p3[1] - p2[1]) / (p3[0] - p2[0])if d1 != d2 and d2 != d3 and d1 != d2:return Trueelse:return False
不需要判断分母为0
def fun2(points):#数学方法p1 = points[0]p2 = points[1]p3 = points[2]if (p1[1]-p2[1])*(p2[0]-p3[0])==(p2[1]-p3[1])*(p1[0]-p2[0]):return Falseelse:return True