Converting polar coordinates to X,Y,Z for 3d plots

조회 수: 4 (최근 30일)
Alex
Alex 2017년 9월 12일
답변: KL 2017년 9월 12일
Hi all, I am rather new in matlab and I am trying to build some code that will help me draw three circle lines (with the same center). This is my first step in plotting measurements conducted in three measurement planes XY,YZ,and XZ that have to be displayed as a 3d plot.
Each of these three planes have associated a number and a degree. For simplification purposes we can assume that number being one. My first idea was to convert the polar coordinates I have (number,degree) to the equivalent X,Y,Z by the code below I wrote in matlab. Feel free to test it and help me find out why those three circles do not have the same center (0,0,0)
X1=turnPolarToX(1,1:360);
Y1=turnPolarToY(1,1:360);
Z1=ones(360);
X2=turnPolarToX(1,1:360);
Y2=ones(360);
Z2=turnPolarToY(1,1:360);
X3=ones(360);
Y3=turnPolarToX(1,1:360);
Z3=turnPolarToY(1,1:360);
plot3(X1,Y1,Z1)
hold on;
plot3(X2,Y2,Z2)
plot3(X3,Y3,Z3)
function d = degreeToRadian(degree)
d = 0.01745329252*degree;
end
function t=turnPolarToX(Amplitude,Coordinate)
t = Amplitude*cos(degreeToRadian(Coordinate))
end
function t=turnPolarToY(Amplitude,Coordinate)
t = Amplitude*sin(degreeToRadian(Coordinate))
end
Thanks a lot for your help. Regards Alex

답변 (2개)

Rik
Rik 2017년 9월 12일
Is there a reason that you can't use the built-in pol2cart? If so, I'll have look at your actual code.

KL
KL 2017년 9월 12일
Because you have ones(360) in all three cases. Change it to zeros(360) and all the circles will be oriented at the origin.

카테고리

Help CenterFile Exchange에서 Polar Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by