附合导线计算程序设计
- 格式:doc
- 大小:36.00 KB
- 文档页数:5
5 附合导线计算程序设计#include<stdio.h>#define PI 3.1415926#include<math.h>#define LEN sizeof(struct node)#include<stdlib.h>struct zuobiao{double x;double y;};struct angle{int degree;int minute;float second;};struct node{double x;double y;struct angle ang1;struct angle fwj;double s;double dx;double dy;struct node *next;};double jtod(struct angle jiao){double degree;degree=jiao.degree;degree+=(jiao.minute/60.0);degree+=(jiao.second/3600.0);return degree;}struct angle dtoj(double jiaodu){struct angle fwj;fwj.degree=floor(jiaodu);fwj.minute =floor((jiaodu-floor(jiaodu))*60);fwj.second =((jiaodu-floor(jiaodu))*60-fwj.minute)*60;return fwj;}double jtoh(struct angle jiaodu){double hu;hu=jtod(jiaodu);hu=hu*PI/180;return hu;}main(){FILE *fp;struct zuobiao zb0,zbN;struct node *head,*p1,*p2;struct angle angle1,f0,fB,fN;int n,i;double t,fBsecond,jiaodu;double fX=0,fY=0,K=0,S=0;fB.degree=0;fB.minute=0;fB.second=0;if((fp=fopen("d:\\pro\\data2.txt","r"))==NULL)printf("cannot open this file\n");fscanf(fp,"%d",&n);fscanf(fp,"%lf%lf",&zb0.x,&zb0.y);fscanf(fp,"%d%d%f",&f0.degree,&f0.minute,&f0.second);fscanf(fp,"%lf%lf",&zbN.x,&zbN.y);fscanf(fp,"%d%d%f",&fN.degree,&fN.minute,&fN.second);fB.degree=f0.degree;fB.minute=f0.minute;fB.second=f0.second;fBsecond=jtod(fB);for(i=0;i<n;i++){fscanf(fp,"%d%d%f",&angle1.degree,&angle1.minute,&angle1.second);fBsecond+=jtod(angle1);fBsecond-=180;if(fBsecond>360) fBsecond-=360;if(fBsecond<0) fBsecond+=360;}fBsecond-=jtod(fN);fBsecond*=3600;printf("%lf\n",fBsecond);fBsecond/=-n;rewind(fp);for(i=0;i<11;i++) fscanf(fp,"%lf",&t);head=p1=p2=(struct node *)malloc(LEN);//fscanf(fp,"%d%d%f",&p1->fwj.degree ,&p1->fwj.minute ,&p1->fwj.second ); for(i=0;i<n;i++){fscanf(fp,"%d%d%f",&p1->ang1.degree ,&p1->ang1.minute ,&p1->ang1.second );p1->ang1.second +=fBsecond;if(p1->ang1.second >=60){p1->ang1.second -=60;p1->ang1.minute +=1;if(p1->ang1.minute >=60){p1->ang1.minute -=60;p1->ang1.degree +=1;}}if(p1->ang1.second <0){p1->ang1.second +=60;p1->ang1.minute -=1;if(p1->ang1.minute <0){p1->ang1.minute +=60;p1->ang1.degree -=1;}}p2->next =p1;p2=p1;p1=(struct node *)malloc(LEN);}p2->next=NULL;p1=head;i=0;do{fscanf(fp,"%lf",&p1->s);printf("s[%d]=%.3lf m\n",i+1,p1->s);S+=p1->s;i++;p1=p1->next ;}while(p1->next!=NULL);p1->s=0;printf("S=%8.3lf m\n",S);p1=head;//p1->dx=p1->s*cos(jtoh(p1->fwj ));//p1->dy=p1->s*sin(jtoh(p1->fwj ));//p1=p1->next;jiaodu=jtod(f0);do{jiaodu+=jtod(p1->ang1);jiaodu-=180;if(jiaodu>360) jiaodu-=360;if(jiaodu<0) jiaodu+=360;p1->fwj =dtoj(jiaodu);p1->dx=p1->s*cos(jtoh(p1->fwj));p1->dy=p1->s*sin(jtoh(p1->fwj));p1=p1->next ;}while(p1->next !=NULL);p1=head;fX=zb0.x;fY=zb0.y;do{fX+=p1->dx;fY+=p1->dy;p1=p1->next ;}while(p1->next !=NULL);fX-=zbN.x;fY-=zbN.y;K=sqrt(fX*fX+fY*fY);K/=S;K=1/K;p1=head;if(K>4000){do{// p2=p1->next ;p1->dx+=(-fX/S*p1->s);// p2->x=p1->x+p2->dx;p1->dy+=(-fY/S*p1->s);// p2->y=p1->y+p1->dy;p1=p1->next ;}while(p1->next !=NULL);p1=head;p1->x=zb0.x+p1->dx;p1->y=zb0.y+p1->dy;do{p2=p1->next;p2->x=p1->x+p2->dx;p2->y=p1->y+p2->dy;p1=p1->next ;}while(p2->next !=NULL);}else printf("the error is out of the limite!"),exit(0);printf("fX=%6.3lfm fY=%6.3lfm fS=%6.3lfm K=1 / %d\n",fX,fY,sqrt(fX*fX+fY*fY),(int)K);p1=head;do{printf("%8.3lf %8.3lf\n",p1->x,p1->y);p1=p1->next;}while(p1->next !=NULL);fclose(fp);if((fp=fopen("d:\\pro\\coordinate.dat","w"))==NULL)printf("cannot open this file!\n");fprintf(fp,"fx=%.3lf m\n",fX);fprintf(fp,"fy=%.3lf m\n",fY);fprintf(fp,"fs=%.3lf m\n",sqrt(fX*fX+fY*fY));fprintf(fp,"K=1 / %d\n",(int)K);fprintf(fp,"The coordinates are(m):\n");p1=head;fprintf(fp,"[1]%8.3lf %8.3lf\n",zb0.x,zb0.y);i=1;do{fprintf(fp,"[%d]%8.3lf %8.3lf\n",i+1,p1->x,p1->y);i++;p1=p1->next;}while(p1->next !=NULL);fclose(fp);}。