📜  找出N边正多边形的旋转对称角度

📅  最后修改于: 2021-05-08 16:22:36             🧑  作者: Mango

给定整数N ,它是规则多边形的边数。任务是找到最小的旋转角度,以使生成的规则多边形具有相似的位置和尺寸,即,新旋转的多边形与初始多边形对称。

例子:

方法:对于任何N边的常规多边形,当旋转360度时,它将与多边形的原始位置对齐。为了找到最小的旋转角度,我们使用正多边形的对称性。对于旋转360 / N度N边正多边形,旋转后的多边形与原始多边形的位置相同,这是N边正多边形的外角。

例如:
考虑N = 4,

下面是上述方法的实现。

C++
// C++ program to find the angle
// of Rotational Symmetry of
// an N-sided regular polygon
 
#include 
using namespace std;
 
// function to find required
// minimum angle of rotation
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 code
int main()
{
    int N = 4;
    cout << "Angle of Rotational Symmetry: "
         << minAnglRot(N);
    return 0;
}


Java
// Java program to find the angle
// of Rotational Symmetry of
// an N-sided regular polygon
import java.io.*;
class GFG
{
 
// function to find required
// minimum angle of rotation
static 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 code
public static void main (String[] args)
{
    int N = 4;
    System.out.println("Angle of Rotational Symmetry: " +
                                          minAnglRot(N));
}
}
 
// This code is contributed by shivanisinghss2110


Python3
# Python3 program to find the angle
# of Rotational Symmetry of
# an N-sided regular polygon
 
# Function to find required
# minimum angle of rotation
def 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 code
if __name__ == '__main__':
     
    N = 4;
     
    print("Angle of Rotational Symmetry: ",
          minAnglRot(N))
 
# This code is contributed by mohit kumar 29


C#
// C# program to find the angle
// of Rotational Symmetry of
// an N-sided regular polygon
using System;
class GFG
{
  
// function to find required
// minimum angle of rotation
static 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 code
public static void Main (string[] args)
{
    int N = 4;
    Console.Write("Angle of Rotational Symmetry: " +
                                     minAnglRot(N));
}
}
  
// This code is contributed by rock_cool


Javascript


输出:
Angle of Rotational Symmetry: 90

时间复杂度: O(1)
辅助空间: O(1)