以弧度读取角度并以度/分/秒转换它们

时间:2010-05-05 04:31:23

标签: matlab geometry

n=0;
disp('This program performs an angle conversion');
disp('input data set to a straight line. Enter the name');
disp('of the file containing the input Lambda in radian:  ');
filename = input('   ','s');
[fid,msg] = fopen(filename,'rt');
if fid < 0
    disp(msg);
else
    A=textscan(fid, '%g',1);
    while ~feof(fid)
        Lambda = A(1);
        n = n + 1;
        A = textscan(fid, '%f',1);
    end
fclose(fid);    
end
Alpha=Lambda*180/pi;
fprintf('Angle converted from radian to degree/minutes/seconds:\n');
fprintf('Alpha      =%12d\n',Alpha);
fprintf('No of angles   =%12d\n',n);  

1 个答案:

答案 0 :(得分:4)

要转换为deg / min / sec到您使用的度数:

Degree = MinutesOfArc/(60 MinutesOfArc/Degree) +
       + SecondsOfArc/(3600 SecondsOfArc/Degree)

例如,45度,30分钟,30秒= 45.508度。因此,您可以执行以下操作来反转该操作:

AlphaDeg = floor(Alpha);
AlphaMinAndSec = (Alpha - AlphaDeg)*60;
AlphaMin = floor(AlphaMinAndSec);
AlphaSec = (AlphaMinAndSec - AlphaMin)*60;

请注意,由于floor操作,这对负输入不起作用。它也比它慢。但如果你的问题是家庭作业,我会让你弄清楚剩下的。