Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matlab 3d mesh and line plotting

Tags:

matlab

I need help plotting a spiral helix on a cone. For the helix:

x = tsin(6t)
y = tcos(6t)
z = t/3

...and this helix lies on the cone:

z = sqrt(x^2+y^2)/3

I need to plot the mesh plot of the cone and the 3D line plot of the helix on the same chart.

like image 313
matlab padawan Avatar asked May 29 '11 21:05

matlab padawan


People also ask

How do you plot a 3-D plot in MATLAB?

plot3( X , Y , Z ) plots coordinates in 3-D space. To plot a set of coordinates connected by line segments, specify X , Y , and Z as vectors of the same length. To plot multiple sets of coordinates on the same set of axes, specify at least one of X , Y , or Z as a matrix and the others as vectors.

What is the difference between mesh and surf in MATLAB?

surf() and mesh() both create Chart Surface Objects in current releases. surf() turns on face coloring by default and uses black edges by default, whereas mesh() turns face coloring off by default and uses colored edges by default.

What command is utilized to do a 3-D mesh plot in MATLAB?

The surf function is used to create a 3-D surface plot.

Can we have multiple 3-D plots in MATLAB?

7. Can we have multiple 3d plots in MATLAB? Explanation: The plot3() function is a pre-defined function in MATLAB. So, it will allow the use to generate multiple 3d plots.


1 Answers

I think you want a surface plot of the cone first. Try

[X Y] = meshgrid(-1:.01:1);
Z = sqrt(X.^2 + Y.^2)/3;

Then, plot this surface with the surf function, and set some sort of shading and transparency

surf(X,Y,Z), caxis([-1 1]), shading flat, alpha(.5);

This should make a cone shape (you can play with the colors).

Now for the helix, define the vectors as you did

t = 0:.01:1;
x = t.*cos(6*t);
y = t.*sin(6*t);
z = t/3;

Then do

hold on;

This makes it so any other plotting you do will appear on the same figure.

Then finally,

plot3(x,y,z);
like image 73
MarkV Avatar answered Sep 28 '22 04:09

MarkV