MATLAB Answers

Plotting two Spherical helix on top of each other with one being 90 deg shifted rotated about the z axis

조회 수: 2(최근 30일)
William Black
William Black 2021년 8월 5일
댓글: William Black 2021년 8월 6일
The code below plots a spherical helix.
What I want is another spherical helix plotted on top but rotated 90deg about the z axis (different colors are to be used for the second helix)
% Set the Order #
Order = 5;
% Set 3D attributes
t = 0:0.01:Order*pi;
% set x, y and z curves
%positive half
xp = sin(-t/Order).*cos(t);
yp = sin(t/Order).*sin(t);
zp = cos(t/Order);
%Negative Half
xn = sin(t/Order).*cos(t);
yn = sin(-t/Order).*sin(t);
zn = cos(t/Order);
% Set figure number
% Plot all curves as defined
plot3(xp, yp, zp, xn, yn, zn);
% Label 3D axis

채택된 답변

Scott MacKenzie
Scott MacKenzie 2021년 8월 5일
편집: Scott MacKenzie 2021년 8월 6일
For a before-and-after comparision, substitute the following for the plot3 line in your code. The z-axis rotation isn't particularly obvious, but look carefully and I think this is what you are after.
nexttile; % plot on left
% this is what the code in the question generates
plot3(xp, yp, zp, xn, yn, zn);
nexttile; % plot on right
% plot 1st curve as is
plot3(xp, yp, zp);
hold on;
% plot 2nd curve with 90 degrees rotation about z-axis
h = plot3(xn, yn, zn);
rotate(h, [0 0 1], 90);
or perhaps...
% this is what the code in the question generates
plot3(xp, yp, zp, xn, yn, zn);
% plot the two curves in separate colors with 2nd curve rotated
plot3(xp, yp, zp, 'b', xn, yn, zn, 'b');
hold on;
h = plot3(xp, yp, zp, 'm', xn, yn, zn, 'm');
rotate(h, [0 0 1], 90);
  댓글 수: 3
William Black
William Black 2021년 8월 6일
No, LOL. Your originally suggested code did not create the visual I needed. But using your technique, I was able to modify my code appropriately.
I was actually looking for a way to modify the equations to produce the phase shift initially, negating the need to visually rotate the image. I will continue to explore this approach. If you have any suggestions, I would be most appreciative.
But your new edited solution as shown above does indeed produce the desired visual.
I'm just beginning to learn the MatLab commands, syntax and, ultimately, realize its potential regarding my work...I may have more questions in the future after become more intrepid.
Thanks again!

댓글을 달려면 로그인하십시오.

추가 답변(0개)




Community Treasure Hunt

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

Start Hunting!

Translated by