Home > Backend Development > C++ > body text

What is the area of ​​an n-sided regular polygon of a given radius?

WBOY
Release: 2023-09-01 20:49:05
forward
677 people have browsed it

Here we will see how to calculate the area of ​​an n-sided regular polygon of a given radius. The radius here is the distance from any vertex to the center. To solve this problem, we draw a vertical line from the center to one of the sides. Assume the length of each side is 'a'. The perpendicular divides the side into two parts, each part having length a/2. A vertical line and a radius form an angle x. Suppose the length of the radius is h.

What is the area of ​​an n-sided regular polygon of a given radius?

Here we can see that the polygon is divided into N equal triangles. Therefore, for any polygon with N sides, it will be divided into N triangles. Therefore, the angle at the center is 360 degrees. This is divided into 360°/N different angles (here 360°/6 = 60°). Therefore, the angle x is 180°/N. Now we can easily get h and a using trigonometric equations.

What is the area of ​​an n-sided regular polygon of a given radius?

Now the area of ​​the entire polygon is N*A.

Example

#include 
#include 
using namespace std;
float polygonArea(float r, int n){
   return ((r * r * n) * sin((360 / n) * 3.1415 / 180)) / 2; //convert
   angle to rad then calculate
}
int main() {
   float rad = 9.0f;
   int sides = 6;
   cout << "Polygon Area: " << polygonArea(rad, sides);
}
Copy after login

Output

Polygon Area: 210.44
Copy after login

The above is the detailed content of What is the area of ​​an n-sided regular polygon of a given radius?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!