#include<stdio.h>
#include<math.h>
#define PI 3.1415926
#define t PI/180
int main(void)
{
int i;
double p0,p1,p2,a0,b0,m,n,l,a5;
double A,B,C,r,s,f1,f2,k1,j; /*定义变量 */
double u1=1.0/45,u2,x0=1.0,xm=2.0,ym=1.414,y0=1.0; /*定自变量、函数与转角的比例尺*/
double a[3],b[3],a1[6],b1[3],k[3];
u2=(sqrt(2)-1)/85;
int ii,jj;
double x[3],y[3];
printf("各结点处的有关各值如下:\n");
for(ii=0;ii<3;ii++)
{
x[ii]=(1.0/2.0*(xm+x0))-(1.0/2.0*(xm-x0)*cos((2*(ii+1)-1)*PI/6));
y[ii]=sqrt(x[ii]);
a[ii]=(x[ii]-x0)/u1;
b[ii]=(y[ii]-y0)/u2;
printf("x[%d]=%-12lf y[%d]=%-12lf α[%d]=%-12lf ψ[%d]=%-12lf\n",ii+1,x[ii],ii+1,y[ii],ii+1,a[ii],ii+1,b[ii]);
}
printf("\n\n");
for (jj=0;jj<10;jj++)
{
printf("please input a0: \n");
scanf("%lf",&a0);
printf("please input ψ0: \n");
scanf("%lf",&b0);// a0=85;b0=30;
for(i=0;i<3;i++)
{
a1[i]=cos((b[i]+b0)*t);
a1[i+3]=cos((b[i]+b0-a[i]-a0)*t);
b1[i]=cos((a[i]+a0)*t);
}
p0=((b1[0]- b1[1])*(a1[4]-a1[5])-(b1[1]-b1[2])*(a1[3]-a1[4]))/((a1[0]-a1[1])*(a1[4]-a1[5])-(a1[1]-a1[2])*(a1[3]-a1[4]));
p1=(b1[0]-b1[1]-(a1[0]-a1[1])*p0)/(a1[3]-a1[4]);
p2=b1[0]-a1[0]*p0-a1[3]*p1;
m=p0;
n=-m/p1;
l=sqrt(m*m+n*n+1-2*n*p2);
printf("p0=%-12lf p1=%-12lf p2=%-12lf \n m=%-12f n=%-12lf l=%-12f\n",p0,p1,p2,m,n,l);
printf("\n");
printf("检查偏差值△ψ,数据如下:\n"); //前面基本没有问题,最后的检查时 r 应该不等于 f1 且 k1<1
for (ii=0;ii<3;ii++)
{
printf("当α=%lf时:\n",a[ii]);
A=sin((a[ii]+a0)*t);
B=cos((a[ii]+a0)*t)-n;
C=(1+m*m+n*n-l*l)/(2*m)-n*cos((a[ii]+a0)*t)/m;
j=x0+u1*a[ii];
printf("A=%-12lf B=%-12lf C=%-12lf\n",A,B,C);
s=sqrt(A*A+B*B-C*C);
if((B+C)<0.0)
{f1=2*(atan((A-s)/(B+C)))/(t)-b0;} //f1=ψ
else if((B+C)>0.0)
{f1=2*(atan((A+s)/(B+C)))/(t)-b0;}
r=(sqrt(j)-y0)/u2; //r=ψ'
k[ii]=f1-r;
printf("ψ=%-12lf ψ'=%-12lf △ψ=%-12lf\n\n",f1,r,k[ii]);
}
if(labs(k[0])<1&&labs(k[1])<1&&labs(k[2])<1)
{
printf("当初始角αo=%.2lf,ψo=%.2lf时:△ψ<1°则初始角合格!\n",a0,b0);
break;
}
printf("试取初始角不合格!请继续试取下一组\n");
}
for(i=0,a5=0;a5<=45;i++,a5+=0.5)
{
printf("当α=%lf时:\n",a5);
A=sin((a5+a0)*t);
B=cos((a5+a0)*t)-n;
C=(1+m*m+n*n-l*l)/(2*m)-n*cos((a5+a0)*t)/m;
j=x0+u1*a5;
printf("A=%-12lf B=%-12lf C=%-12lf\n",A,B,C);
s=sqrt(A*A+B*B-C*C);
if((B+C)>0)
f1=2*(atan(A+s)/(B+C))/(t)-b0; //f1=ψ的正值
else if((B+C)<0)f1=2*(atan((A-s)/(B+C)))/(t)-b0;//f1=ψ的负值
r=(sqrt(j)-y0)/u2; //r=ψ'
k1=f1-r;
printf("ψ=%-12lf ψ'=%-12lf △ψ=%-12lf\n",f1,r,k1);
printf("\n\n");
}
return 0;
}
{