Coordinates Function please I need help
3 ビュー (過去 30 日間)
古いコメントを表示
I am working on this function where I have to give the coordinates of a specific point in the 4 quadrants in radians and degrees , I have been working on it and still have not been able to figure it out please I need some help.
if true
function [th rad]=cartopolar25(x,y)
th=atan(y/x);
rad=sqrt(x^2+y^2);
if x>0
return
y>0
th=th;
else
if x>0
return
y<0
th=-th;
else
if x<0
return
y>0
th=180+th;
else
th=-180+th;
end
end
end
% code
end
0 件のコメント
回答 (1 件)
Image Analyst
2013 年 7 月 20 日
That is not proper syntax. First of all, if x > 0 you return so it never ever gets a chance to do the y>0 line (which is useless anyway), or the equally useless th=th line. Why not just make it simple and have 4 cases for the 4 quadrants:
if x>0 && y>0
% Code
elseif x>0 && y<0
% Code
elseif x<0 && y>0
% Code
elseif x<0 && y<0
% Code
end
2 件のコメント
Image Analyst
2013 年 7 月 20 日
I think you can do it if you think hard enough about it. Just change the sign of th and add or subtract an angle as necessary to get the right value for the quadrant. I think you can do it even if I don't do the first one for you because you're a smart engineer and this is just 10th grade trigonometry.
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!