程式檢查 Python 中兩個三角形是否全等
在本教程中,我們將檢查兩個三角形的全等關係。我們將檢視 SSS、SAS 和 AAA。三角形的相似性是根據這些準則證明的。
我們必須根據定理檢查不同的條件。在下面的程式碼中檢查它們。
示例
def side_side_side(sides_one, sides_two):
# sorting same pace
sides_one.sort()
sides_two.sort()
# checking the conditions
if sides_one[0] / sides_two[0] == sides_one[1] / sides_two[1] \
and sides_one[1] / sides_two[1] == sides_one[2] / sides_two[2] \
and sides_one[2] / sides_two[2] == sides_one[0] / sides_two[0]:
return True
return False
def side_angle_side(sides_one, sides_two, angles_one, angles_two):
# sorting same pace
sides_one.sort()
sides_one.sort()
angles_one.sort()
angles_one.sort()
# checking conding 1
if sides_one[0] / sides_two[0] == sides_one[1] / sides_two[1]:
if angles_one[0] == angles_two[0]:
return True
# checking conding 2
if sides_one[1] / sides_two[1] == sides_one[2] / sides_two[2]:
if angles_one[1] == angles_two[1]:
return True
# checking conding 3
if sides_one[2] / sides_two[2] == sides_one[0] / sides_two[0]:
if angles_one[2] == angles_two[2]:
return True
# return False if any of the above conditions are not satisfied
return False
def angle_angle_angle(angles_one, angles_two):
# sorting same pace
angles_one.sort()
angles_two.sort()
# checking the conditions
if angles_one[0] == angles_two[0] \
or angles_one[1] == angles_two[1] \
or angles_one[2] == angles_two[2]:
return True
return False
if __name__ == '__main__':
# initialzing the sides
sides_one = [2.0, 3.0, 3.0]
sides_two = [4.0, 6.0, 6.0]
# initialzing the angles
angles_one = [80.0, 60.0, 40.0]
angles_two = [40.0, 60.0, 80.0]
# checking the printing the respective property
print("Triangles are similar by:", end=' ')
if side_side_side(sides_one, sides_two):
print("SSS", end=' ')
if side_angle_side(sides_one, sides_two, angles_one, angles_two):
print("SAS", end=' ')
if angle_angle_angle(angles_one, angles_two):
print("AAA", end='')輸出
如果您執行上述程式碼,則將獲得以下結果。
Triangles are similar by: SSS SAS AAA
結論
如果您對本教程有任何疑問,請在評論部分中提及。
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP