from distance import point
class point1(point):
#判断3个点组成的三角形类型
def judgeTriangle(self, p1, p2):
self_p1 = self.distance(p1)
self_p2 = self.distance(p2)
p1_p2 = p1.distance(p2)
# 该点与p1的距离最大
if self_p1 > self_p2 and self_p1 > p1_p2:
if self_p1 > (self_p2 + p1_p2):
print('不是三角形')
else:
#利用余玄定理很容易得出
if self_p1 **2 > (self_p2 ** 2 + p1_p2 ** 2):
print("钝角三角形")
elif self_p1 ** 2<(self_p2 ** 2 + p1_p2 ** 2):
print("锐角三角形")
else:
print("直角三角形")
# 该点与p2的距离最大
if self_p2 > self_p1 and self_p2 > p1_p2:
if self_p2 > (self_p1 + p1_p2):
print('不是三角形')
else:
if self_p2 ** 2 > (self_p1 ** 2 + p1_p2 ** 2):
print("钝角三角形")
elif self_p2 ** 2<(self_p1 ** 2 + p1_p2 ** 2):
print("锐角三角形")
else:
print("直角三角形")
# 该点与p3的距离最大
if p1_p2 > self_p1 and p1_p2 > self_p2:
if p1_p2 > (self_p1 + self_p2):
print('不是三角形')
else:
if p1_p2 ** 2 > (self_p1 ** 2 + self_p2 ** 2):
print("钝角三角形")
elif p1_p2**2 <(self_p1 ** 2 + self_p2 ** 2):
print("锐角三角形")
else:
print("直角三角形")
if __name__ == '__main__':
pt=point1(3, 0)
pt.judgeTriangle(point1(3,4), point1(0,0))
联系客服