Write a Python program to check whether a point (x,y) is in a triangle or not. There is a triangle formed by three points.
x1,y1,x2,y2,x3,y3,xp,yp separated by a single space.
print("Input x1,y1,x2,y2,x3,y3,xp,yp:") x1,y1,x2,y2,x3,y3,xp,yp = map(float, input().split()) c1 = (x2-x1)*(yp-y1)-(y2-y1)*(xp-x1) c2 = (x3-x2)*(yp-y2)-(y3-y2)*(xp-x2) c3 = (x1-x3)*(yp-y3)-(y1-y3)*(xp-x3) if (c1<0 and c2<0 and c3<0) or (c1>0 and c2>0 and c3>0): print("The point is in the triangle.") else: print("The point is outside the triangle.")
Input x1,y1,x2,y2,x3,y3,xp,yp: 2 3 4 5 6 8 7 1 The point is outside the triangle.
Write a Python program to check whether a point (x,y) is in a triangle or not
Disclaimer: The information and code presented within this recipe/tutorial is only for educational and coaching purposes for beginners and developers. Anyone can practice and apply the recipe/tutorial presented here, but the reader is taking full responsibility for his/her actions. The author (content curator) of this recipe (code / program) has made every effort to ensure the accuracy of the information was correct at time of publication. The author (content curator) does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause. The information presented here could also be found in public knowledge domains.