根据题意,设theta为弧对应角度的一半,则有等式:
- 增加的高度h = L*tan(theta/2)/2。
- sin(theta)/theta = 1/(1+n*c)。
2式中的sin(theta)/theta,即sinc(theta)是信号处理中常见的振荡函数,当theta在[0,pi/2]之间时此函数为单调递减函数,所以可以根据等式右边的值使用二分不断逼近正确的theta值。
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
#define sinc(x) sin(x)/(x)
#define precision 0.000000000001
#define pi 3.1415926535897932384626433832795028
double calc_theta(double y)
{
double left = 0;
double right = pi/2.0;
double mid;
while(left < right)
{
mid = (left+right)/2.0;
if(sinc(mid) < y) //sinc(x)在[0,pi/2]之间为单调递减函数
right = mid-precision;
else if(sinc(mid) > y)
left = mid+precision;
else
return mid;
}
return left;
}
int main()
{
double L;
double degree;
double c;
double dest;
double theta;
while(scanf("%lf%lf%lf",&L,°ree,&c)&&(L != -1))
{
if(L == 0 || degree == 0 || c == 0)
printf("0.000\n");
else
{
dest = 1.0/(1+degree*c);
theta = calc_theta(dest);
printf("%.3f\n",L*tan(theta/2.0)/2.0);
}
}
return 0;
}