MATLAB Answers

Add 2d plots along a 3d helix

7 views (last 30 days)
Vivi
Vivi on 13 Feb 2020
Commented: Vivi on 13 Feb 2020
Hello.
I have a simple helix that I've plotted by using the following code:
r=93.36;
theta=0:pi/50:10*pi;
%Trajectory in x-direction
x=-r.*cos(theta);
%Trajectory in y-direction
y=r.*sin(theta);
%Trajectory in z-direction
z=theta;
figure(1);
plot3(x,y,z);
xlabel('x');
ylabel('y');
zlabel('z');
grid on
My goal now is to also plot on the same graph the x and y components of the helix given from the equations above.
Thank you.

  0 Comments

Sign in to comment.

Accepted Answer

Subhadeep Koley
Subhadeep Koley on 13 Feb 2020
Use this
close all; clc;
r=93.36;
theta=0:pi/50:10*pi;
%Trajectory in x-direction
x=-r.*cos(theta);
%Trajectory in y-direction
y=r.*sin(theta);
%Trajectory in z-direction
z=theta;
figure(1);
plot3(x,y,z);
xlabel('x');
ylabel('y');
zlabel('z');
grid on
hold on;
plot(x, y, 'r', 'LineWidth', 3);

  3 Comments

Vivi
Vivi on 13 Feb 2020
Thank you but i want two plots where the first one is a plot of x against theta and then seconf a plot of y against theta as well.
Subhadeep Koley
Subhadeep Koley on 13 Feb 2020
@ Vivi I am not sure but it seems you want something like below
close all; clc;
r = 93.36;
theta = 0: pi/50: 10*pi;
% Trajectory in x-direction
x = -r .* cos(theta);
% Trajectory in y-direction
y = r .* sin(theta);
% Trajectory in z-direction
z = theta;
figure;
plot3(x, y, z, 'b');
xlabel('x');
ylabel('y');
zlabel('z');
grid on; box on;
hold on;
% Plot x against theta
axis([-101 101 -101 101 -1 36]);
SX = size(x);
Y3 = 101 * ones(SX);
plot3(x, Y3, z, 'r', 'LineWidth', 1.5);
% Plot y against theta
SY = size(y);
X3 = 101 * ones(SY);
plot3(X3, y, z, 'g', 'LineWidth', 1.5);
hold off;
Vivi
Vivi on 13 Feb 2020
That's the one. Thank you!

Sign in to comment.

More Answers (0)


Translated by