# Program to check congruency of two triangles

Given four arrays of 3 numbers each which represents sides and angles of two triangles. The task is to check if the two triangles are Congruent or not. Also print the theorem by which they are congruent.

**Note:** All sides and angles given as input are for valid triangles.

**Examples:**

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

Congruent triangles are two or more triangles that have all corresponding sides that are equal or a pair of sides and between angle are equal or a pair of angle and side between are equal or a pair of angle and other side are equal or hypotenuse and one side are equal.

The congruency of triangles can be proved by the following theorems:

**Side-Side-Side (SSS) Congruency criteria:**If all the sides of a triangle are equal to the sides of another triangle then the triangles are said to be congruent by the property of*Side-Side-Side*(SSS).

In above triangle ABC and A’B’C’ if, AB=A’B’ and BC=B’C’ and CA=C’A’ then, triangles are congruent.**Side-Angle-Side (SAS) Congruent criteria:**If two sides of the two triangles are equal and the angle between them is same in both triangle then the triangles are said to be congruent by the property of*Side-Angle-Side*(SAS). In above triangle ABC and A’B’C’ if, AB=A’B’ and BC=B’C’ and = triangles are congruent.**Angle-Side-Angle (ASA) Congruent criteria :**If two angles of the two triangles are equal and the length of side between them is same in both triangle then the triangles are said to be congruent by the property of*Angle-Side-Angle*(ASA).In above triangle ABC and A’B’C’ if, =

and = and BC=B’C’ then, triangles are congruent.**Angle-Angle-Side (AAS) Congruent criteria :**If two angles of the two triangles are equal and the length of other side is same in both triangle then the triangles are said to be congruent by the property of*Angle-Angle-Side*(AAS). In above triangle ABC and A’B’C’ if, = and = and CA=C’A’ then, triangles are congruent.**Hypotenuse-Leg (HL) Congruent criteria :**

If the hypotenuse of the two triangles are equal and the length of any other one side is same in both triangle then the triangles are said to be congruent by the property of*Hypotenuse-Leg*(HL).

Below is the implementation of the above theorems.

`# 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"` |

*chevron_right*

*filter_none*

**Output:**

Triangles are congruent by SSS SAS ASA AAS HL

## Recommended Posts:

- Program to check similarity of given two triangles
- Program to print the pattern with two hollow Triangles
- Count the number of possible triangles
- Equilateral Triangles using Matchsticks
- Number of triangles after N moves
- Find all possible triangles with XOR of sides zero
- Number of triangles that can be formed
- Number of triangles that can be formed with given N points
- Area of the circumcircle of any triangles with sides given
- Count number of right triangles possible with a given perimeter
- Counting Triangles in a Rectangular space using BIT
- Count number of unique Triangles using STL | Set 1 (Using set)
- Number of Triangles in an Undirected Graph
- Program to check for ISBN
- Program to check if two strings are same or not

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.