📜  求 N 边正多边形的旋转对称角

📅  最后修改于: 2021-10-23 08:13:03             🧑  作者: Mango

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

例子:

处理方法:对于任意一个N边的正多边形,当旋转 360 度时,它在多边形的原始位置对齐。为了找到最小旋转角度,我们使用正多边形的对称性。对于N边正多边形旋转360/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)

如果您希望与专家一起参加现场课程,请参阅DSA 现场工作专业课程学生竞争性编程现场课程