打酱油,说个
题外话,假如不按照题目的要求去做的话:
设输入比例为 a : b
先计算出 θ,使得 θ- sinθ = 2*M_PI*a/(a+b)
然后弦长等于 sqrt( 2 - 2*cosθ )
程序代码:
#include <stdio.h>
#define _USE_MATH_DEFINES // for VC
#include <math.h>
double arc_length( unsigned a, unsigned b )
{
const double temp = 2*M_PI*a/(a+b);
double x_lo=0, x_hi=2*M_PI;
double y_lo=0, y_hi=2*M_PI;
while( x_hi-x_lo > 0.000001 )
{
double x = (x_lo+x_hi)/2;
double y = x - sin(x);
if( y < temp )
{
x_lo = x;
y_lo = y;
}
else
{
x_hi = x;
y_hi = y;
}
}
return sqrt(2-2*cos(x_lo));
}
int main( void )
{
printf( "%f\n", arc_length(1,1) );
printf( "%f\n", arc_length(1,2) );
printf( "%f\n", arc_length(10,1) );
}