Plotting 3D by rotate 2D plot around y-axis

I have a question to draw a 3D cup of coffe (no need to draw a handle). I think to be easy we need to draw 2 parabol ( inner and outter ) , the upper bound and bottom bound, then rotate that 2D plot around y-axis, but I dont have any idea and knowledge to do that, is there another way ? Can anyone help me with this, many thanks

 採用された回答

Star Strider
Star Strider 2023 年 3 月 23 日

2 投票

Probably the easiest way is to define a cylinder and a shape vector —
yv = [linspace(0.3, 1, 50)];
ys1 = yv.*exp(-1.75*yv)*5;
ys2 = (1-exp(-25*(yv-0.3)))*0.7;
figure
plot(ys1, yv)
hold on
plot(ys2, yv)
hold off
grid
% xlim([0 1.5])
axis ('equal')
[X1,Y1,Z1] = cylinder(ys1,50);
[X2,Y2,Z2] = cylinder(ys2,50);
figure
surf(X1,Y1,Z1, 'EdgeColor','interp', 'FaceAlpha',0.5) % Outer Surface
hold on
surf(X2,Y2,Z2, 'EdgeColor','interp') % Inner Survface
patch([X1(end,:) X2(end,:)], [Y1(end,:) Y2(end,:)], [Z1(end,:) Z2(end,:)], 'r', 'EdgeColor','r') % Top Rim
patch([X1(1,:) X2(1,:)], [Y1(1,:) Y2(1,:)], [Z1(1,:) Z2(1,:)], 'b', 'EdgeColor','b') % Lower Surface
hold off
colormap(turbo)
This demonstrates the construction approach, and setting the outer ‘FaceAlphs’ value to shows the internal structure as well.
Experiment with the ‘ys1’ and ‘ys2’ shape vectors to get the result you want. To get the inner and outer thicknesses, it will likely be necessary to use two cyllinder objects with different shapes, and the hold function to plot both of them on the same axes. The patch call creating the top rim will autoomatically adapt to whatever the inner and outer contour functions are. Another patch call can provide a solid lower surface as well, if that is necessary. (I use the turbo colormap her because I like it. Choose the appropriate colormap for your plot.)
.

4 件のコメント

Tuan
Tuan 2023 年 3 月 23 日
OMG you did exactly what I means. The upper bound and bottem bound is very neccesary as well (as I mention in my question). Can I ask how to measure the size of the cup too (7.3cm and 5.5cm). Where shoud I edit to get what I want, thank you so much
Star Strider
Star Strider 2023 年 3 月 24 日
yv = linspace(0.25, 5, 50);
yoc = yv.*exp(-0.45*yv)+0.5;
yic = (1-exp(-25*(yv-0.2)))*0.9;
figure
plot(yoc*7.3/2, yv, 'DisplayName','Outer Contour')
hold on
plot(yic*5.5/2, yv, 'DisplayName','Inner Contour')
hold off
grid
% xlim([0 1.5])
axis ('equal')
title('Half Cross-Section Elevation')
legend('Location','best')
PMF = 7.3/2;
[X1,Y1,Z1] = cylinder(yoc*PMF,50);
[X2,Y2,Z2] = cylinder(yic*PMF,50);
Z1 = Z1*max(yv);
Z2 = Z2*max(yv);
XYT = PMF+1;
figure
surf(X1+XYT,Y1+XYT,Z1, 'EdgeColor','interp', 'FaceAlpha',0.25) % Outer Surface
hold on
surf(X2+XYT,Y2+XYT,Z2, 'EdgeColor','interp') % Inner Survface
patch([X1(end,:) X2(end,:)]+XYT, [Y1(end,:) Y2(end,:)]+XYT, [Z1(end,:) Z2(end,:)], 'r', 'EdgeColor','r') % Top Rim
patch([X1(1,:) X2(1,:)]+XYT, [Y1(1,:) Y2(1,:)]+XYT, [Z1(1,:) Z2(1,:)], 'b', 'EdgeColor','b') % Lower Surface
hold off
% axis('equal')
colormap(turbo)
view(33,20)
This is the best I can do. It has the approximate height and approximate diameter as desired. It might be necessary to draw the outer contour, since I am not certain that it can be approximated mathematically, at least without a lot of experimentation, and getting the diameters at the base and rim correct appears to be critical.
.
Tuan
Tuan 2023 年 3 月 24 日
thank you a lot, that is all i need , hope you the best <3
Star Strider
Star Strider 2023 年 3 月 24 日
As always, my pleasure!
Thank you! You, too!

サインインしてコメントする。

その他の回答 (1 件)

KSSV
KSSV 2023 年 3 月 23 日

0 投票

1 件のコメント

Tuan
Tuan 2023 年 3 月 23 日
Thanks but this still a static image, what i mean is create a 3D object with this

サインインしてコメントする。

カテゴリ

製品

質問済み:

2023 年 3 月 23 日

コメント済み:

2023 年 3 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by