

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Apothem of a n-sided regular polygon in C++
n-sided regular polygon is a closed figure of n sides that has all sides and angles of equal length. The below figure shows a 6 sided regular polygon commonly known as hexagon.
Apothem is a line in the polygon that connects the center of the figure to the side. And it is perpendicular to one of its sides that makes it smallest in length.
Now, let drive the formula for its length.
The angle made by the side of an n sided polygon is 360/n.
Now, as in the figure, the angle is equal to (360 / n )/2 = 180 /n
Now taking the triangle, we can conclude that
tan ø = b/2 / h = b/2h 2h * tan ø = b h = b/2*tanø , ø = 180 /n h = b/2*tan(180/n)
Let's implement this to a program to find the length of apothem when the number of sides and length of each side of the polygon are given.
Formula
Given n = number of side , b = length of each side. h = length of apothem, h = b/2 * tan(180/n)
Example
#include<iostream> #include <math.h> using namespace std; void apothemLength(int n, float a){ if (a < 0 && n < 0) cout<<"invalid values"; else cout<<"the length of apothem = "<< (a/(2*tan((180/n)*3.14159/180))); } int main(){ float a = 12; int n = 9; apothemLength(n, a); return 0; }
Output
the length of apothem = 16.4849
- Related Questions & Answers
- Area of a n-sided regular polygon with given Radius?
- Area of a n-sided regular polygon with given Radius in C Program?
- Area of a n-sided regular polygon with given side length in C++
- Area of largest Circle inscribed in N-sided Regular polygon in C Program?
- Area of largest Circle inscribe in N-sided Regular polygon in C Program?
- Determine the position of the third person on regular N sided polygon in C++?
- Determine the position of the third person on regular N sided polygon in C++ Program
- Find number of diagonals in n sided convex polygon in C++
- Probability that the pieces of a broken stick form a n sided polygon in C++
- Area of a polygon with given n ordered vertices in C++
- Program to find the Circumcircle of any regular polygon in C++
- Program to find the Interior and Exterior Angle of a Regular Polygon in C++
- Program to count number of isosceles triangle from colored vertex regular polygon in Python
- Laplace transform and Region of Convergence for right-sided and left-sided signals
- Center of each side of a polygon in JavaScript
Advertisements