Plotting 3D truncated cone in matlab - matlab

How can I plot a 3D nodes in a shape of truncated cone using matlab, and I want to connect each two nodes together with line.

Here is a truncated cone (based on http://msemac.redwoods.edu/~darnold/math50c/matlab/coordcyl/index.xhtml). I'm not sure if this is the type of mesh you are looking for.
r=linspace(1,2,25);
theta = linspace(0,2*pi,25);
[r,theta] = meshgrid(r,theta);
x = r.*cos(theta);
y = r.*sin(theta);
z = -r;
mesh(x,y,z)

Related

Creating meshgrid of scattered Cartesian data for plotting on a sphere

I have a set of n=8000 cartesian coordinates X,Y and Z as vectors and also a vector V of same size which I want to use as values to create a heatmap on a sphere.
I saw this link (visualization of scattered data over a sphere surface MATLAB), but I don't understand how I convert this set of data into a meshgrid for plotting using surf.
Almost every example I saw uses meshgrids.
Right now, I am doing by plotting a sphere and then use scatter3 to plot my points as big balls and try to smooth them later. I looks like this:
I would like to get the figure as the plotting of the example in that link, where he uses:
k = 5;
n = 2^k-1;
[x,y,z] = sphere(n);
c = hadamard(2^k);
surf(x,y,z,c);
colormap([1 1 0; 0 1 1])
axis equal
EDIT:
(Sorry for taking so long to reply, the corona crises kept away from work)
What I am actually doing is:
for i=1:numel(pop0n)
ori(i,:)=ori(i,:)/norm(ori(i,:));
end
x = ori(:,1);
y = ori(:,2);
z = ori(:,3);
%// plot
m=100;
[aa,bb,cc] = sphere(m);
surf(aa,bb,cc,ones(m+1,m+1)*min(pop0n))
hold on
colormap jet;
scatter3(x,y,z,400,pop0n/norm(pop0n),'filled');
colorbar
shading interp
The array 'ori' is 8000x3, and contains the x, y and z coordinates of the points I want to plot and pop0n is a 8000 sized vector with the intensities of each coordinate.
My main question is how do I transform my x, y, z and pop0n, that are vectors, into 2D arrays (meshgrid) to use surf?
Because I cannot simply do surf(x,y,z,pop0n) if they are vectors.
Thanks in advance
As David suggested, griddata does the job.
What I did was:
for i=1:numel(pop0n)
ori(i,:)=ori(i,:)/norm(ori(i,:));
end
x = ori(:,1);
y = ori(:,2);
z = ori(:,3);
%// plot
m=100;
[aa,bb,cc] = sphere(m);
v = griddata(x,y,z,pop0n,aa,bb,cc,'nearest');
surf(aa,bb,cc,v)
colormap jet;
colorbar
shading interp

How to calculate the volume under two intersection surface?

I like to calculate the volume under the two intersection plane. The two plane is draw use this code.
P1 = [575,0,400];
P2 = [287.5,0,662];
P3 = [575,3500,154];
normal = cross(P1-P2, P1-P3)
syms x y z
P = [x, y, z]
ep1=dot(normal, P-P1)
% get the equation
Z = solve(ep1,z)
% draw the first plane
ezsurf(Z,[287.5,575,0,3500])
hold on
% draw the second horizontal plane
[x,y]=meshgrid(0:500:3500)
z = ones(8,8)*440
surf(x, y, z)
So I must calculate the volume under the first plane.
I used this code, but I don't know how to construct matrix Zm used the the symbols equation Z. And how can I use meshgrid and surf not ezsurf draw the first plane.
%f=#(x,y)(interp2(Zm,Xq,Yq))
% I want to calculate volume under the plane ranged by Xmin=2.875, Xmax=575,Ymin=0,Ymax=3500
%volume = quad2d(f,(287.5),575,0,3500)
%volume = integral2(f,287.5,575,0,3500)
Thanks a lot.
As an alternative strategy that might be easier to understand I would suggest, instead of interpolating, using some geometry formulas to calculate the area. You can break down the 3D shape into a simple triangular prism and an irregular tetrahedron. There are well defined generalized formulas for both of these.
http://mathcentral.uregina.ca/QQ/database/QQ.09.03/peter2.html

How to plot a 3D surface with a circle in it?

I have a rational polynomial function. I find zeros of numerator and denominator of it. Now I want to draw this function and I do it with meshgrid and mesh command in matlab. How can I draw a circle in this shape? I add my result figure at first and second figure is an image that I want to be like that( draw red circle).
Create x and y for your circle:
r = 1;
theta = 0:0.1:2*pi;
x = r*cos(theta);
y = r*sin(theta);
Get the value of your function at the x and y's and plot a line in 3D with the values:
z = f(x,y);
plot3(x,y,z);
The final result may have some artefacts where the line crosses in and out of the surface. If you are not so concerned about the accuracy in the plot add a very small value to z to "lift" it above the surface.

How to create a 2d color map plot from x and y coordinates and a vector of values?

I'm trying to plot a 2 dimensional signal on a specific plane in a 3d model. I have the matrix:
xyzp (nx3)
that contains all the points which are closest to the plane (e.g. when the plane is in the z direction, all the z coordinates are fairly similar).
and I have a vector:
signal (nx1)
that contains a value for each point in xyzp.
when I use:
"surf([xyzp(:,[1,2]),signal)" or "mesh([xyzp(:,[1,2]),signal])"
The plot I get doesn't look at all like the intersection of the plane with the model from any angle (I expected "view(2)" to show the signal in the Z direction), so I assume I didn't use the plot function correctly.
Can anyone show me an example? For instance - A circle on an xy plane with some random signal indicated by color
surf and mesh can be used when the points form a rectangular grid on the xy plane.
In the general case (points are arbitrarily placed), you can use scatter3. For purposes of illustration, consider the following example xyzp and signal:
[x y] = ndgrid(-1:.01:1);
x = x+.3*y; %// example values which do not form a rectangular grid
z = x+y; %// example z as a function of x, y
xyzp = [x(:) y(:) z(:)];
signal = z(:)+x(:)-y(:); %// example values
Then
scatter3(xyzp(:,1), xyzp(:,2), xyzp(:,3), 1, signal, '.');
produces the following figure.
Since scatter3 plots each point separately, the picture is not as smooth as it would be with surf. But this seems hard to improve if the coordinates do not a have any "structure" (as surf requires) .

2D plot in 3D polar graph

I would like to plot a 3D graph, y=100-x^2, cycle around the Y axis in 360 degrees. Eventually to become like a cone. Is that possible? I have an array x=1:1:100, and an array y, size(1 100).
I tried an Z array, z=1:1:100 as the 3th axis in the base of the cone. With plot3 I done the one graph of y=100-x^2. I would like to kinda animate it and have eventually a cone, or a surface cone.
Is this what you are looking for?
r = 1:1:100;
y = 100-r.^2;
theta = 0:pi/20:2*pi;
xx = bsxfun(#times,r',cos(theta));
zz = bsxfun(#times,r',sin(theta));
yy = repmat(y',1,length(theta));
surf(xx,yy,zz)
Source: Generating a 3D plot by revolution of a curve