Inscribed Circles and Isosceles Triangles
Given two real numbers
B
the width of the base of an isosceles triangle in inches H
Compute to six significant decimal places
C
For those whose geometry and trigonometry are a bit rusty, the center of an inscribed circle is at the point of intersection of the three angular bisectors.
Input
The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.
The input will be a single line of text containing two positive single precision real numbers (BH) separated by spaces.
Output
For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.
The output should be a single real number with twelve significant digits, six of which follow the decimal point. The decimal point must be printed in column 7.
Sample Input
1 0.263451 0.263451
Sample Output
0.827648
借鉴一下这个图片,讲的很清楚
代码:
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
using namespace std;
int main()
{
int T;
double pi = acos(-1.0);
scanf("%d",&T);
while(T--)
{
double a,h;
scanf("%lf%lf",&a,&h);
double k;///等腰三角形相等的两个夹角的值
double r;///内切圆的半径
double sum = 0;
double h1 = h;
k = atan(h/(a/2));
r = tan(k/2) * (a/2);
if(r>=0.000001)
{
sum = sum + 2 * r * pi;
}
while(1)
{
h1 = h;
h = h - (2 * r);
a = a * (h/h1);
r = tan(k/2) * (a/2);
if(r<0.000001)
{
break;
}
sum = sum + 2 * r * pi;
}
printf("%13.6lf\n",sum);
if(T!=0)
{
printf("\n");
}
}
return 0;
}