Find the angle of Rotational Symmetry of an N-sided regular polygon - GeeksforGeeks

31 Mar, 2021
Given an integer N which is the number of sides of a regular polygon. The task is to find the smallest angle of rotation such that the generated regular polygons have a similar position and dimensions, i.e. the new rotated polygon is in symmetry with the initial one.
A shape is said to have a rotation symmetry if there exists a rotation in the range [1, 360o] such that the new shape overlaps the initial shape completely.
Examples:  
Input: N = 4 Output: 90 Explanation: A 4 sided regular polygon is a square and when it is rotated by 90 degrees it results in the similar square.
Input: N = 8 Output: 45  
Approach: For any N sided regular polygon, when rotated by 360 degrees, it aligns in the original position of the polygon. To find the minimum angle of rotation we use the property of symmetry of regular polygons. For an N sided regular polygon when rotated by 360/N degrees, the rotated polygon is in the same position as of the original polygon, which is the exterior angle of an N-sided regular polygon.
For example: Consider N = 4, 
Below is the implementation of the above approach. 
C++
Java
Python3
C#
Javascript
// C++ program to find the angle// of Rotational Symmetry of// an N-sided regular polygon #include <bits/stdc++.h>using namespace std; // function to find required// minimum angle of rotationdouble minAnglRot(int N){    // Store the answer in    // a double variable    double res;     // Calculating the angle    // of rotation and type-    // casting the integer N    // to double type    res = 360 / (double)N;     return res;} // Driver codeint main(){    int N = 4;    cout << "Angle of Rotational Symmetry: "         << minAnglRot(N);    return 0;}
// Java program to find the angle// of Rotational Symmetry of// an N-sided regular polygonimport java.io.*;class GFG{ // function to find required// minimum angle of rotationstatic double minAnglRot(int N){    // Store the answer in    // a double variable    double res;     // Calculating the angle    // of rotation and type-    // casting the integer N    // to double type    res = 360 / (double)N;     return res;} // Driver codepublic static void main (String[] args){    int N = 4;    System.out.println("Angle of Rotational Symmetry: " +                                          minAnglRot(N));}} // This code is contributed by shivanisinghss2110
# Python3 program to find the angle# of Rotational Symmetry of# an N-sided regular polygon # Function to find required# minimum angle of rotationdef minAnglRot(N):         # Store the answer in a    # variable         # Calculating the angle    # of rotation and type-    # casting the integer N    # to type    res = 360 // N     return res # Driver codeif __name__ == '__main__':         N = 4;         print("Angle of Rotational Symmetry: ",          minAnglRot(N)) # This code is contributed by mohit kumar 29   
// C# program to find the angle// of Rotational Symmetry of// an N-sided regular polygonusing System;class GFG{  // function to find required// minimum angle of rotationstatic double minAnglRot(int N){    // Store the answer in    // a double variable    double res;      // Calculating the angle    // of rotation and type-    // casting the integer N    // to double type    res = 360 / (double)N;      return res;}  // Driver codepublic static void Main (string[] args){    int N = 4;    Console.Write("Angle of Rotational Symmetry: " +                                     minAnglRot(N));}}  // This code is contributed by rock_cool
<script> // Javascript program to find the angle// of Rotational Symmetry of an N-sided// regular polygon // Function to find required// minimum angle of rotationfunction minAnglRot(N){         // Store the answer in    // a double variable    let res;     // Calculating the angle of    // rotation and type-casting    // the integer N to double type    res = 360 / N;     return res;} // Driver codelet N = 4; document.write("Angle of Rotational Symmetry: " +               minAnglRot(N)); // This code is contributed by divyeshrabadiya07 </script>
Angle of Rotational Symmetry: 90
 
Time Complexity: O (1) Auxiliary Space: O (1) 
mohit kumar 29
shivanisinghss2110
rock_cool
divyeshrabadiya07
Geometric
Mathematical
Mathematical
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Convex Hull | Set 1 (Jarvis's Algorithm or Wrapping)
Closest Pair of Points | O(nlogn) Implementation
Line Clipping | Set 1 (Cohen–Sutherland Algorithm)
Given n line segments, find if any two segments intersect
Convex Hull | Set 2 (Graham Scan)
Program for Fibonacci numbers
C++ Data Types
Write a program to print all permutations of a given string
Set in C++ Standard Template Library (STL)
Coin Change | DP-7