测量程序设计实验报告实验名称:坐标正反算-1-实验三坐标正反算一、实验目的编写坐标正反算程序,并对格式化文件数据进行计算,验证程序。二、实验内容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;dms=degree+mimute/100+second/10000;度分秒转度:functiondegree=dms2degree(jiaodu)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=fix(a)%b=(a-l)*60.0%m=fix(b)%a=l+m/100.0+(b-m)*0.006-2-%if(rad0)%dms=-a;%else%dms=a;%enddegree=fix(jiaodu);mimute=fix((jiaodu-degree)*60);second=((jiaodu-degree)*60-mimute)*60;dms=degree+mimute/100+second/10000;if(rad0)dms=-dms;elsedms=dms;endreturnfunction[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,filename];data=importdata(file);%[x1,y1]=data.data(:,[1,2]);-3-azimuth=dms2degree(data.data(:,4));distance=data.data(:,3);%[x2,y2]=xy_direct(x1,y1,distance,azimuth);[x2,y2]=xy_direct(data.data(:,1),data.data(:,2),distance,azimuth);[filename_out,pathname_out]=uiputfile;fileout=[pathname_out,filename_out];fid=fopen(fileout,'wt');fprintf(fid,'x1y1x2y2\n');fprintf(fid,'%8.2f%8.2f%8.2f%8.2f\n',[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,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;elseifdelt_x(i)0&&delt_y(i)0azimuth(i)=2*pi-azimuth_temp;elseifdelt_x(i)0&&delt_y(i)0azimuth(i)=pi-azimuth_temp;-4-elsedelt_x(i)0&&delt_y(i)0;azimuth(i)=pi+azimuth_temp;endendazimuth=rad2dms(azimuth)distance=sqrt((x2-x1).^2+(y2-y1).^2);%fprintf('两点间距离:%8.3f;方位角为:%8.3f',distance,azimuth);2)对文件data2.txt中数据进行坐标反算,并将计算结果按照格式存贮在文件data3.txt中,Data3.txt格式为:x1y1x2y2距离方位角(dd.mmss)[filename,pathname]=uigetfile;file=[pathname,filename];data=importdata(file);[distance,azimuth]=xy_inv(data.data(:,1),data.data(:,2),data.data(:,3),data.data(:,4));[filename_out,pathname_out]=uiputfile;fileout=[pathname_out,filename_out];fid=fopen(fileout,'wt');fprintf(fid,'x1y1x2y2距离方位角(dd.mmss)\n');fprintf(fid,'%8.2f%8.2f%8.2f%8.2f%8.2f%8.4f\n',[data.data(:,1:4),distance,azimuth']');fclose('all');3、可能用到的函数开根号,sqrt(x)sin(rad)、cos(rad)、atan2(y,x),find