《基于matlab的坐标正反算(共7页).docx》由会员分享,可在线阅读,更多相关《基于matlab的坐标正反算(共7页).docx(7页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精选优质文档-倾情为你奉上测量程序设计实验报告实验名称:坐标正反算实验三 坐标正反算一、实验目的编写坐标正反算程序,并对格式化文件数据进行计算,验证程序。二、实验内容1、编写坐标正算程序1) 建立以xy_direct命名的函数,函数输入输出格式为 x2,y2 = xy_direct(x1,y1,distance, azimuth)度转度分秒: function dms= degree2dms(jiaodu)degree = fix(jiaodu);mimute = fix(jiaodu-degree)*60);second = (jiaodu-degree)*60-mimute)*60;dms
2、 = degree+mimute/100+second/10000;度分秒转度: function degree = dms2degree(jiaodu)degree = fix(jiaodu); mimute = fix(jiaodu-degree)*100);second = (jiaodu-degree-mimute/100)*10000; degree = degree+mimute/60+second/3600;弧度转度: function dms=rad2dms(rad) rad=abs(rad); jiaodu=rad*180.0/pi; % l=fix(a) % b=(a-l)
3、*60.0 % m=fix(b) % a=l+m/100.0+(b-m)*0.006 % if(rad % 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; if(rad function x2,y2 = xy_direct(x1,y1,distance, azimuth)x2=x1+distance.*cos(azimu
4、th*pi/180);y2=y1+distance.*sin(azimuth*pi/180);end2) 对文件data1.txt中数据进行坐标正算,并将已知点和计算点坐标按照格式存贮在文件data2.txt中,data1.txt格式为: x1 y1 距离 方位角(dd.mmss)data2.txt格式为: x1 y1 x2 y2 filename,pathname=uigetfile; file=pathname,filename; data=importdata(file); %x1,y1=data.data(:,1,2); azimuth=dms2degree(data.data(:,4
5、); 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,x1 y1 x2 y2n); fprintf(fid,%8.2f %8.2f %8.2f %8.2fn,data.da
6、ta(:,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); for i=1:m azimuth_temp=atan2(abs(delt_y(i),abs(delt_x(i); if delt_x(i)
7、0&delt_y(i)0 azimuth(i)=azimuth_temp; elseif delt_x(i)0&delt_y(i)0 azimuth(i)=2*pi-azimuth_temp; elseif delt_x(i)0 azimuth(i)=pi-azimuth_temp; else delt_x(i)0&delt_y(i) azimuth=rad2dms(azimuth) distance=sqrt(x2-x1).2+(y2-y1).2); %fprintf(两点间距离:%8.3f ;方位角为:%8.3f,distance,azimuth);2) 对文件data2.txt中数据进行
8、坐标反算,并将计算结果按照格式存贮在文件data3.txt中,Data3.txt格式为: x1 y1 x2 y2 距离 方位角(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, x1 y1 x2 y2 距离 方位角(dd.mmss)n);fprintf(fid,%8.2f %8.2f %8.2f %8.2f %8.2f %8.4fn,data.data(:,1:4),distance,azimuth);fclose(all);3、可能用到的函数 开根号,sqrt(x)sin(rad)、cos(rad)、atan2(y,x),find专心-专注-专业