Given a n-sided regular polygon and three vertices **a1**, **a2** and **a3**, the task is to find the angle suspended at vertex a1 by vertex a2 and vertex a3.

**Examples:**

Input:n = 6, a1 = 1, a2 = 2, a3 = 4Output:90Input:n = 5, a1 = 1, a2 = 2, a3 = 5Output:36

**Approach:**

- The angle subtended by an edge on the center of n sided regular polygon is
**360/n**. - The angle subtended by vertices seperated by k edges becomes
**(360*k)/n**. - The chord between the vertices subtends an angle with half the value of the angle subtended at the center at the third vertex which is a point on the circumference on the circumcircle.
- Let the angle obtained in this manner be
**a = (180*x)/n**where k is number of edges between i and k. - Similarily for the opposite vertex we get the angle to be
**b = (180*y)/n**where l is number of edges between j and k. - The angle between the three vertices thus equals
**180-a-b**.

Below is the implementation of the above approach:

## C++

`// C++ implementation of the approach ` ` ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function that checks whether given angle ` `// can be created using any 3 sides ` `double` `calculate_angle(` `int` `n, ` `int` `i, ` `int` `j, ` `int` `k) ` `{ ` ` ` `// Initialize x and y ` ` ` `int` `x, y; ` ` ` ` ` `// Calculate the number of vertices ` ` ` `// between i and j, j and k ` ` ` `if` `(i < j) ` ` ` `x = j - i; ` ` ` `else` ` ` `x = j + n - i; ` ` ` `if` `(j < k) ` ` ` `y = k - j; ` ` ` `else` ` ` `y = k + n - j; ` ` ` ` ` `// Calculate the angle subtended ` ` ` `// at the circumference ` ` ` `double` `ang1 = (180 * x) / n; ` ` ` `double` `ang2 = (180 * y) / n; ` ` ` ` ` `// Angle subtended at j can be found ` ` ` `// using the fact that the sum of angles ` ` ` `// of a triangle is equal to 180 degrees ` ` ` `double` `ans = 180 - ang1 - ang2; ` ` ` `return` `ans; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `n = 5; ` ` ` `int` `a1 = 1; ` ` ` `int` `a2 = 2; ` ` ` `int` `a3 = 5; ` ` ` ` ` `cout << calculate_angle(n, a1, a2, a3); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the approach ` `class` `GFG ` `{ ` ` ` `// Function that checks whether given angle ` `// can be created using any 3 sides ` `static` `double` `calculate_angle(` `int` `n, ` `int` `i, ` ` ` `int` `j, ` `int` `k) ` `{ ` ` ` `// Initialize x and y ` ` ` `int` `x, y; ` ` ` ` ` `// Calculate the number of vertices ` ` ` `// between i and j, j and k ` ` ` `if` `(i < j) ` ` ` `x = j - i; ` ` ` `else` ` ` `x = j + n - i; ` ` ` `if` `(j < k) ` ` ` `y = k - j; ` ` ` `else` ` ` `y = k + n - j; ` ` ` ` ` `// Calculate the angle subtended ` ` ` `// at the circumference ` ` ` `double` `ang1 = (` `180` `* x) / n; ` ` ` `double` `ang2 = (` `180` `* y) / n; ` ` ` ` ` `// Angle subtended at j can be found ` ` ` `// using the fact that the sum of angles ` ` ` `// of a triangle is equal to 180 degrees ` ` ` `double` `ans = ` `180` `- ang1 - ang2; ` ` ` `return` `ans; ` `} ` ` ` `// Driver code ` `public` `static` `void` `main (String[] args) ` `{ ` ` ` `int` `n = ` `5` `; ` ` ` `int` `a1 = ` `1` `; ` ` ` `int` `a2 = ` `2` `; ` ` ` `int` `a3 = ` `5` `; ` ` ` ` ` `System.out.println((` `int` `)calculate_angle(n, a1, a2, a3)); ` `} ` `} ` ` ` `// This code is contributed by Rajput-Ji ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of the approach ` ` ` `# Function that checks whether given angle ` `# can be created using any 3 sides ` `def` `calculate_angle(n, i, j, k): ` ` ` ` ` `# Initialize x and y ` ` ` `x, y ` `=` `0` `, ` `0` ` ` ` ` `# Calculate the number of vertices ` ` ` `# between i and j, j and k ` ` ` `if` `(i < j): ` ` ` `x ` `=` `j ` `-` `i ` ` ` `else` `: ` ` ` `x ` `=` `j ` `+` `n ` `-` `i ` ` ` `if` `(j < k): ` ` ` `y ` `=` `k ` `-` `j ` ` ` `else` `: ` ` ` `y ` `=` `k ` `+` `n ` `-` `j ` ` ` ` ` `# Calculate the angle subtended ` ` ` `# at the circumference ` ` ` `ang1 ` `=` `(` `180` `*` `x) ` `/` `/` `n ` ` ` `ang2 ` `=` `(` `180` `*` `y) ` `/` `/` `n ` ` ` ` ` `# Angle subtended at j can be found ` ` ` `# using the fact that the sum of angles ` ` ` `# of a triangle is equal to 180 degrees ` ` ` `ans ` `=` `180` `-` `ang1 ` `-` `ang2 ` ` ` `return` `ans ` ` ` `# Driver code ` `n ` `=` `5` `a1 ` `=` `1` `a2 ` `=` `2` `a3 ` `=` `5` ` ` `print` `(calculate_angle(n, a1, a2, a3)) ` ` ` `# This code is contributed by Mohit Kumar ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the approach ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// Function that checks whether given angle ` `// can be created using any 3 sides ` `static` `double` `calculate_angle(` `int` `n, ` `int` `i, ` ` ` `int` `j, ` `int` `k) ` `{ ` ` ` `// Initialize x and y ` ` ` `int` `x, y; ` ` ` ` ` `// Calculate the number of vertices ` ` ` `// between i and j, j and k ` ` ` `if` `(i < j) ` ` ` `x = j - i; ` ` ` `else` ` ` `x = j + n - i; ` ` ` `if` `(j < k) ` ` ` `y = k - j; ` ` ` `else` ` ` `y = k + n - j; ` ` ` ` ` `// Calculate the angle subtended ` ` ` `// at the circumference ` ` ` `double` `ang1 = (180 * x) / n; ` ` ` `double` `ang2 = (180 * y) / n; ` ` ` ` ` `// Angle subtended at j can be found ` ` ` `// using the fact that the sum of angles ` ` ` `// of a triangle is equal to 180 degrees ` ` ` `double` `ans = 180 - ang1 - ang2; ` ` ` `return` `ans; ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main () ` `{ ` ` ` `int` `n = 5; ` ` ` `int` `a1 = 1; ` ` ` `int` `a2 = 2; ` ` ` `int` `a3 = 5; ` ` ` ` ` `Console.WriteLine((` `int` `)calculate_angle(n, a1, a2, a3)); ` `} ` `} ` ` ` `// This code is contributed by ihritik ` |

*chevron_right*

*filter_none*

**Output:**

36

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- How to check if a given point lies inside or outside a polygon?
- Calculate the angle between hour hand and minute hand
- Find other two sides of a right angle triangle
- Check if a path exists in a tree with K vertices present or are at most at a distance D
- Find if it's possible to rotate the page by an angle or not.
- Program to find the Interior and Exterior Angle of a Regular Polygon
- Check if it is possible to create a polygon with a given angle
- Angle between two Planes in 3D
- Probability that the pieces of a broken stick form a n sided polygon
- Number of ways a convex polygon of n+2 sides can split into triangles by connecting vertices
- Area of a largest square fit in a right angle triangle
- Area of a circle inscribed in a regular hexagon
- Find other two sides and angles of a right angle triangle
- Program to find the Circumcircle of any regular polygon
- Program to find the Perimeter of a Regular Polygon
- Side of a regular n-sided polygon circumscribed in a circle
- Diagonal of a Regular Pentagon
- Diagonal of a Regular Hexagon
- Diagonal of a Regular Heptagon
- Diagonal of a Regular Decagon

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.