Is there a possibility to draw several cylinders or tubes in a matlab figure - matlab

I have 3-D plot in matlab and it contain several lines. I want to draw cylinder or hollow tubes around those line. Is someone has experience of plotting several cylinder in 3-D plot?

Yes, there is a possibility. There is a possibility of everything in Matlab!
Lets Google and find: cylinder()!
Fantastic, Matlab has a function to generate cylinders!
And... That's it. Go plot them wherever you want.
Fun:
clear;clc;
cmap = hsv(10);
for ii=1:10
hold on
[X,Y,Z]=cylinder(rand(1,1)*0.4);
h=surf(X+(rand(1,1)-10)*2,Y+(rand(1,1)-10)*2,Z*rand(1,1)*10,'FaceColor',cmap(ii,:));
end

Related

Draw surface of 3D cloud in matlab

I have 3D cloud of dots. I need to plot them as a surface. I tried variant with meshdrid, griddata, scatteredInterpolant,trisurf-delaunay. Nothing works. I know that this question was discussed a lot, but it seems I don't understand some important details. The code which i have now:
load('coords.mat')
figure()
subplot(1,2,1)
plot3(x,y,z,'.')
axis off
view(3)
subplot(1,2,2)
C=gray(numel(x)); % unsuccessful attempt
[~,idx]=sort(z); % to have
C=C(idx,:); % illumination
scatter3(x,y,z,50,C,'filled')
axis off
view(3)
produces the following image:
Could you help me:
1) to find a way to draw it with surface function.
and as some dots may be inside the surface (may be it is my problem)
2) How to remove 'invisible' dots?
I need solution for different cases, picture and data presents just an example.
Mat file may be downloaded here.
P.S.
In case it is important – I obtain coordinates of this dots as a rotation of random bezier curve.
UPDATE
In case data above is too big I generate another set with smaller amount of dots:
Coordinates are here.
where do you get this data from? It is represented as vectors but if you reshape it to matrices you can use the surf function. Try this code:
z=reshape(z,100,100);
y=reshape(y,100,100);
x=reshape(x,100,100);
surf(x,y,z)

Plot 3D surface that is not the graph of a function

I have a 3D data set of a surface that is not a function graph. The data is just a bunch of points in 3D, and the only thing I could think of was to try scatter3 in Matlab. Surf will not work since the surface is not a function graph.
Using scatter3 gave a not so ideal result since there is no perspective/shading of any sort.
Any thoughts? It does not have to be Matlab, but that is my go-to source for plotting.
To get an idea of the type of surface I have, consider the four images:
The first is a 3D contour plot, the second is a slice in a plane {z = 1.8} of the contour. My goal is to pick up all the red areas. I have a method to do this for each slice {z = k}. This is the 3rd plot, and I like what I see here a lot.
Iterating this over z give will give a surface, which is the 4th plot, which is a bit noisy (though I have ideas to reduce the noise...). If I plot just the black surface using scatter3 without the contour all I get is a black indistinguishable blob, but for every slice I get a smooth curve, and I have noticed that the curves vary pretty smoothly when I adjust z.
Some fine-tuning will give a much better 4th plot, but still, even if I get the 4th plot to have no noise at all, the result using scatter3 will be a black incomprehensible blob when plotted alone and not on top of the 3D contour. I would like to get a nice picture of the full surface that is not plotted on top of the 3D contour plot
In fact, just to compare and show how bad scatter3 is for surfaces, even if you had exact points on a sphere and used scatter3 the result would be a black blob, and wouldn't even look like a sphere
Can POV-Ray handle this? I've never used it...
If you have a triangulation of your points, you could consider using the trisurf function. I have used that before to generate closed surfaces that have no boundary (such as polyhedra and spheres). The downside is that you have to generate a triangulation of your points. This may not be ideal to your needs but it definitely an option.
EDIT: As #High Performance Mark suggests, you could try using delaunay to generate a triangulation in Matlab
just wanted to follow up on this question. A quick nice way to do this in Matlab is the following:
Consider the function d(x, y, z) defined as the minimum distance from (x, y, z) to your data set. Make sure d(x, y, z) is defined on some grid that contains the data set you're trying to plot.
Then use isosurface to plot a (some) countour(s) of d(x, y, z). For me plotting the contour 0.1 of d(x, y ,z) was enough: Matlab will plot a nice looking surface of all points within a distance 0.1 of the data set with good lighting and all.
In povray, a blob object could be used to display a very dense collection of points, if you make them centers of spheres.
http://www.povray.org/documentation/view/3.6.1/71/
If you want to be able to make slices of "space" and have them colored as per your data, then maybe the object pattern (based on a #declared blob object) might do the trick.
Povray also has a way to work with df3 files, which I've never worked with, but this user appears to have done something similar to your visualization.
http://paulbourke.net/miscellaneous/df3/

Plotting 3-D Matrix *values* in MATLAB

I have a 3D Matrix M(256x256x136) and each index(i,j,k) in M has a gray level value in it. I am interested in displaying M in some sort of a 3D plot in MATLAB, but am unable to do so. I cannot use plot3 because plot3 is for plotting points, not the values.
Thanks
If I understand your question correctly, you want to plot the 3D point cloud with i,j, and k as 3D coordinates and the gray level as the point value.
I would suggest using scatter3.
Sounds like you are looking for a volume renderer. For Matlab, you could try this one: Volume Render from Matlab Central
An isosurface plot might be useful as well.

3D scatterplot colored by Z-Value

I've been googling for a while but couldn't find a solution for my problem. I am an amateur matlab user and I would like to create a 3D scatterplot, for this I have a matrix containing several points in 3D space:
>> size(A)
ans =
2511 3
I was able to create a 3D scatterplot using "scatter3" function, but now I am stuck a bit at color-coding the 3D points.
scatter3(A(:,1),A(:,2),A(:,3));
This will plot the data, but now I would like to add a color coding based on the z-Value...
The colors themself don't matter too much. It could be a rainbow spectrum or a temperature spectrum or whatever. I just would like to colorcode them to distinguish the z-Values of the points.
Can anybody help me with this? Thank you!
You have to give some more arguments to scatter3.
scatter3(X,Y,Z,S,C);
S lets you specify areas for each markers (with a vector) or a single area for all the markers, while C lets you specify color. If C is a vector, its values will be linearly mapped to the current colormap. To change the colormap, call colormap(jet) for example. See the documentation on colormap.
Sorry if that's confusing. Short version:
scatter3(A(:,1),A(:,2),A(:,3),9,A(:,3));
colormap(jet); %# or other colormap

Plotting images over a graph in Matlab

Does anyone know how can one plot() a regular 2D plot in Matlab,
and draw little images over that plot?
Thanks for any tips.
Hmmm, my bad, it's all there in the basic Matlab commands:
You do your plot(),
call 'hold on',
and then call 'image(x,y,img)' to plot that image on top of the existing plot.
:)