📜  程序检查两个三角形的一致性

📅  最后修改于: 2021-04-29 06:37:35             🧑  作者: Mango

给定四个由3个数字组成的数组,每个数组代表两个三角形的边和角。任务是检查两个三角形是否相等。还要打印它们一致的定理。

注意:输入的所有边和角度均为有效三角形。

例子:

Input : side1 = [3, 4, 5]  angle1 = [90, 60, 30]
        side2 = [4, 3, 5]  angle2 = [60, 30, 90]
Output: Triangles are congruent by SSS SAS ASA AAS HL.  

Input : side1 = [3, 5, 6]  angle1 = [80, 50, 50]
        side2 = [1, 1, 1]  angle2 = [60, 60, 60]
Output: Triangles are not congruent

同等三角形是两个或多个三角形,其所有对应边均相等或一对边且角度之间相等,或一对角与边之间的边相等或一对角度与另一边相等或斜边且一个边相等。

三角形的等价性可以通过以下定理证明:

  1. 侧面(SSS)一致标准:如果一个三角形的所有边都等于另一个三角形的边,则这些三角形被称为具有“侧面” (SSS)的性质。
    在上面的三角形ABC和A’B’C’中,如果AB = A’B’和BC = B’C’和CA = C’A’,则三角形是全等的。
  2. 斜角(SAS)同等判据:如果两个三角形的两个边相等,并且两个三角形之间的夹角相同,则称这些三角形因斜角(SAS)的性质而全等。在上面的三角形ABC和A’B’C’中,如果AB = A’B’和BC = B’C’并且\measuredangle ABC = \measuredangle A'B'C'三角形是全等的。
  3. 角-边-角(ASA)同等判据:如果两个三角形的两个角相等,并且两个三角形之间的边长相同,则根据角-边-角(( ASA)。如果在三角形ABC和A’B’C’中, \measuredangle ABC =
    \measuredangle A'B'C'\measuredangle BCA = \measuredangle B'C'A'并且BC = B’C’则三角形是全等的。
  4. 角-边-边(AAS)一致标准:如果两个三角形的两个角相等,并且两个三角形中另一边的长度相同,则根据“角-边-边” (AAS)的性质,称这些三角形是全等的)。在上面的三角形ABC和A’B’C’中, \measuredangle ABC = \measuredangle A'B'C'\measuredangle BCA = \measuredangle B'C'A'并且CA = C’A’,那么三角形是全等的。
  5. 斜边腿(HL)一致标准:
    如果这两个三角形的斜边相等并且任何其他一个边的长度是在两个三角形相同,则三角形被说成是由斜边-腿(HL)的特性一致。

以下是上述定理的实现。

# Python program to check 
# similarity between two triangles.
   
# Function for SAS congruency
def cong_sas(s1, s2, a1, a2): 
       
    s1 = [float(i) for i in s1]
    s2 = [float(i) for i in s2]
    a1 = [float(i) for i in a1]
    a2 = [float(i) for i in a2]
       
    s1.sort()
    s2.sort()
    a1.sort()
    a2.sort()
       
    # Check for SAS
       
    # angle b / w two smallest sides is largest.
    if s1[0] == s2[0] and s1[1] == s2[1]:
           
        # since we take angle b / w the sides.
        if a1[2] == a2[2]:         
            return 1
               
    if s1[1] == s2[1] and s1[2] == s2[2]:
        if a1[0] == a2[0]:
            return 1
               
    if s1[2] == s2[2] and s1[0] == s2[0]:
        if a1[1] == a2[1]:
            return 1
       
    return 0
      
# Function for ASA congruency
def cong_asa(s1, s2, a1, a2): 
       
    s1 = [float(i) for i in s1]
    s2 = [float(i) for i in s2]
    a1 = [float(i) for i in a1]
    a2 = [float(i) for i in a2]
       
    s1.sort()
    s2.sort()
    a1.sort()
    a2.sort()
       
    # Check for ASA
       
    # side b / w two smallest angle is largest.
    if a1[0] == a2[0] and a1[1] == a2[1]:
           
        # since we take side b / w the angle.
        if s1[2] == s2[2]:         
            return 1
               
    if a1[1] == a2[1] and a1[2] == a2[2]:
        if s1[0] == s2[0]:
            return 1
               
    if a1[2] == a2[2] and a1[0] == a2[0]:
        if s1[1] == s2[1]:
            return 1
       
    return 0
      
# Function for AAS congruency
def cong_aas(s1, s2, a1, a2): 
       
    s1 = [float(i) for i in s1]
    s2 = [float(i) for i in s2]
    a1 = [float(i) for i in a1]
    a2 = [float(i) for i in a2]
       
    s1.sort()
    s2.sort()
    a1.sort()
    a2.sort()
       
    # Check for AAS
       
    # side other two smallest angle is smallest or 2nd smallest.
    if a1[0] == a2[0] and a1[1] == a2[1]:
           
        # since we take side other than angles.
        if s1[0] == s2[0] or s1[1] == s2[1]:         
            return 1
               
    if a1[1] == a2[1] and a1[2] == a2[2]:
        if s1[1] == s2[1] or s1[2] == s2[2]:
            return 1
               
    if a1[2] == a2[2] and a1[0] == a2[0]:
        if s1[0] == s2[0] or s1[2] == s2[2]:
            return 1
       
    return 0
   
# Function for HL congruency
def cong_hl(s1, s2): 
       
    s1 = [float(i) for i in s1]
    s2 = [float(i) for i in s2] 
    s1.sort()
    s2.sort() 
       
    # Check for HL
    if s1[2] == s2[2]:
        if s1[1] == s2[1] or s1[0] == s2[0]:
            return 1
       
    return 0
      
# Function for SSS congruency
def cong_sss(s1, s2): 
       
    s1 = [float(i) for i in s1]
    s2 = [float(i) for i in s2] 
    s1.sort()
    s2.sort() 
       
    # Check for SSS
    if(s1[0] == s2[0] and s1[1] == s2[1] and s1[2] == s2[2]):
        return 1
       
    return 0
       
   
# Driver Code 
s1 = [3, 4, 5]
s2 = [4, 3, 5]
           
a1 = [90, 60, 30]
a2 = [60, 30, 90]
   
# function call for SSS congruency
sss = cong_sss(s1, s2) 
   
# function call for SAS congruency 
sas = cong_sas(s1, s2, a1, a2) 
  
# function call for ASA congruency 
asa = cong_asa(s1, s2, a1, a2) 
   
# function call for AAS congruency
aas = cong_aas(s1, s2, a1, a2)
  
# function call for HL congruency
hl = cong_hl(s1, s2, ) 
   
# Check if triangles are congruent or not 
if sss or sas or asa or aas or hl : 
    print "Triangles are congruent by",
    if sss: print "SSS", 
    if sas: print "SAS",
    if asa: print "ASA",
    if aas: print "AAS",
    if hl: print "HL",
else: print "Triangles are not congruent"
输出:
Triangles are congruent by SSS SAS ASA AAS HL