Hello! I am experiencing some problems when trying to plot a cone in ML using the fsurf function.
When using meshgrid and surf everything works as expected (the height of the cone is supposed to be three times the radius, that's where the formula for z comes from):
radius = 2;
r = linspace(0,radius);
phi = linspace(0,2*pi);
[R, PHI] = meshgrid(r,phi);
X = R .* cos(PHI)
Y = R .* sin(PHI)
Z = -3*R + 3 * radius;
surf(X,Y,Z);
I have this example for a cylinder in ML:
R = 2;
xZ = @(t,z) R*cos(t);
yZ = @(t,z) R*sin(t);
zZ = @(t,z) z;
fsurf(xZ, yZ, zZ);
This example works fine but I guess I have not really understood how everything comes together or how these anonymus functions work. I think this example can be modified to plot a cone by altering zZ but I do not really know how. Maybe someone can give me a push in the right direction.

 采纳的回答

I have found a solution and in case anyone should come across the same problem:
xCone = @(s,t) (coneRadius - 1/3 * t) .* cos(s);
yCone = @(s,t) (coneRadius - 1/3 * t) .* sin(s);
zCome = @(s,t) t;
fsurf(xCone, yCone, zCone, [0, 2*pi, 0, 3*coneRadius]);
This will plot a 3D cone with a given radius (coneRadius) using fsurf. It is important to know that this cone has a fixed height of three times its radius.

2 个评论

Congratulations! +1!
I could not get my code to work when I experimented with it to see if I could provide a working result.
Note that the last function should be:
zCone = @(s,t) t;
Typographical errors make our lives more interesting!
Haha, yes, they do. :) Will fix the typo now.
However: It is important to know that this cone has a fixed height of three times its radius. (Which was a requirement in this specific task.)

请先登录,再进行评论。

更多回答(0 个)

产品

Community Treasure Hunt

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

Start Hunting!

Translated by