fork download
  1. class Point:
  2. def __init__(self,x,y):
  3. self.x = x
  4. self.y = y
  5. def checkCollinearity(P1,P2,P3):
  6. if P1.x*(P2.y-P3.y) - P1.y*(P2.x-P3.x) + P2.x*P3.y - P2.y*P3.x == 0:
  7. return True
  8. else:
  9. return False
  10. def main():
  11. Points = []
  12. for i in range(3):
  13. print("Point#%d"%(i+1))
  14. x = float(input("abs="))
  15. y = float(input("ord="))
  16. P = Point(x,y)
  17. Points.append(P)
  18. #method 1 with Slope
  19. if Points[0].x == Points[1].x or Points[0].x == Points[2].x:
  20. if Points[0].x == Points[2].x:
  21. print("Collinear.")
  22. else:
  23. print("No Collinear.")
  24. else:
  25. if((Points[1].y - Points[0].y)/(Points[1].x - Points[0].x) == (Points[2].y - Points[1].y)/(Points[2].x - Points[1].x)):
  26. print("Collinear.")
  27. else:
  28. print("No Collinear.")
  29.  
  30. #method 2 with Sarrus
  31. if(checkCollinearity(Points[0], Points[1], Points[2]) is True):
  32. print("Collinear.")
  33. else:
  34. print("No Collinear.")
  35. main()
  36.  
Success #stdin #stdout 0.05s 9732KB
stdin
1 
2
3 
4 
5 
6
stdout
Point#1
abs=ord=Point#2
abs=ord=Point#3
abs=ord=Collinear.
Collinear.