UVA Problem 10432 – Polygon Inside A Circle Solution:
Click here to go to this problem in uva Online Judge.
Solving Technique:
This is a rather easy geometry / computational geometry problem. Given the radius of a Circumscribed circle and count of sides of a polygon the task is to find the area of the polygon. A Circumscribed circle is a circle that passes through all vertices of a plane figure and contains the entire figure in its interior.
The formula below can be written into a single formula by combining all the formulas. More information and the combined formula can be found here.
Learn more about regular polygon here including the formula.
Visual Explanation:
I have tried to explain the concept below using figures. They are not drawn to scale. The small circles represent intersection point between polygon vertices and the circumscribed circle.
Example:
It is an example with radius, r = 2 and sides, n = 8.
Important: Be sure to add or print a new line after each output unless otherwise specified. The outputs should match exactly because sometimes even a space character causes the answer to be marked as wrong answer. Please compile with c++ compiler as some of my codes are in c and some in c++.
More Inputs of This Problem on uDebug.
Input:
2 2000 10 3000
Output:
12.566 314.159
Code:
/** * Author: Asif Ahmed * Site: https://quickgrid.wordpress.com * Problem: UVA 10432 - Polygon Inside A Circle * Technique: circumcircle Or, Isocele Area calculation. */ #include<stdio.h> #include<string.h> #include<math.h> int main(){ //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); double r; int n; while( scanf( "%lf%d", &r, &n ) == 2 ){ // Angle between each two points for every point. double PHI = ( double ) 360 / n ; // For each Isosceles in the polygon the angle between the base and radius. double THETA = (double) 90 - ( PHI / 2 ); // Convert Degree angle to Radian to use in code. double THETA_RADIAN = THETA * M_PI / 180; // a is base. double a = 2 * r * cos( THETA_RADIAN ); // H is the height. double h = r * sin( THETA_RADIAN ); // S represent Area of a single segment. double S = (a * h) / 2; // S * n is the are of complete polygon. printf("%.3lf\n", S * n ); } return 0; }
You must be logged in to post a comment.