资源描述:
《基于matlab的坐标正反算.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、测量程序设计实验报告实验名称:坐标正反算-6-实验三坐标正反算一、实验目的编写坐标正反算程序,并对格式化文件数据进行计算,验证程序。二、实验内容1、编写坐标正算程序1)建立以xy_direct命名的函数,函数输入输出格式为[x2,y2]=xy_direct(x1,y1,distance,azimuth)度转度分秒:>>functiondms=degree2dms(jiaodu)>>degree=fix(jiaodu);>>mimute=fix((jiaodu-degree)*60);>>second=((jiaodu-degree)*60-mimute)*60;>>
2、dms=degree+mimute/100+second/10000;度分秒转度:>>functiondegree=dms2degree(jiaodu)-6->>degree=fix(jiaodu);>>mimute=fix((jiaodu-degree)*100);>>second=(jiaodu-degree-mimute/100)*10000;>>degree=degree+mimute/60+second/3600;弧度转度:>>functiondms=rad2dms(rad)>>rad=abs(rad);>>jiaodu=rad*180.0/pi;>>%l
3、=fix(a)>>%b=(a-l)*60.0>>%m=fix(b)>>%a=l+m/100.0+(b-m)*0.006>>%if(rad<0)>>%dms=-a;>>%else>>%dms=a;>>%end>>degree=fix(jiaodu);>>mimute=fix((jiaodu-degree)*60);>>second=((jiaodu-degree)*60-mimute)*60;>>dms=degree+mimute/100+second/10000;-6->>if(rad<0)dms=-dms;elsedms=dms;endreturn>>functi
4、on[x2,y2]=xy_direct(x1,y1,distance,azimuth)>>x2=x1+distance.*cos(azimuth*pi/180);>>y2=y1+distance.*sin(azimuth*pi/180);>>end2)对文件data1.txt中数据进行坐标正算,并将已知点和计算点坐标按照格式存贮在文件data2.txt中,data1.txt格式为:x1y1距离方位角(dd.mmss)data2.txt格式为:x1y1x2y2>>[filename,pathname]=uigetfile;>>file=[pathname,filena
5、me];>>data=importdata(file);>>%[x1,y1]=data.data(:,[1,2]);>>azimuth=dms2degree(data.data(:,4));>>distance=data.data(:,3);>>%[x2,y2]=xy_direct(x1,y1,distance,azimuth);-6->>[x2,y2]=xy_direct(data.data(:,1),data.data(:,2),distance,azimuth);>>[filename_out,pathname_out]=uiputfile;>>fileout
6、=[pathname_out,filename_out];>>fid=fopen(fileout,'wt');>>fprintf(fid,'x1y1x2y2');>>fprintf(fid,'%8.2f%8.2f%8.2f%8.2f',[data.data(:,1:2),x2,y2]);>>fclose('all')ans=02、编写坐标反算程序1)建立以xy_inv命名的函数,函数输入输出格式为[distance,azimuth]=xy_inv(x1,y1,x2,y2)>>function[distance,azimuth]=xy_inv(x1,y1,x2
7、,y2)>>delt_x=x2-x1;>>delt_y=y2-y1;>>[m,x]=size(delt_x);>>azimuth=zeros(0,m);>>fori=1:mazimuth_temp=atan2(abs(delt_y(i)),abs(delt_x(i)));ifdelt_x(i)>0&&delt_y(i)>0azimuth(i)=azimuth_temp;-6-elseifdelt_x(i)>0&&delt_y(i)<0azimuth(i)=2*pi-azimuth_temp;elseifdelt_x(i)<0&&delt_y(i)>0azimut