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.

 채택된 답변

Laura Schimmler
Laura Schimmler 2019년 11월 5일
편집: Laura Schimmler 2019년 11월 5일

2 개 추천

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!
Laura Schimmler
Laura Schimmler 2019년 11월 5일
편집: Laura Schimmler 2019년 11월 5일
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