Rolve function around axis to create 3D surface.

Hello,
I am fairly new to matlab and know the basics. I am trying to create a 3D surface from the function y by revolving it around the x axis. The function is the profile of the tip of a bullet and I am looking to obtain a 3D plot. Thank you in advance!
x = linspace(0,1,100);
y = (2).*(x./12).^0.5;

 採用された回答

Star Strider
Star Strider 2020 年 6 月 30 日

1 投票

4 件のコメント

MLP
MLP 2020 年 6 月 30 日
Hi! thank you for forwarding me to the answer. Although I seem to have an issue, the axis of rotation is at the other extreme of the function and I do not know how to specify the lenght. Here I attached a sketch of what I am looking for in hopes you can help me. I couldn't attach an image for the resultant figure.
figure(); hold on;
for theta = linspace(0, 2*pi, 50) % Not exactly sure how you want to vary theta
[T, R] = meshgrid(linspace(0, theta, 50), linspace(0,2,50));
[X, Y] = pol2cart(T,R);
Z = (2).*(R./12).^0.5; % Compute the surface of revolution
surf(X,Y,Z); % Plot the surface
pause(1); % Wait one second
end
Star Strider
Star Strider 2020 年 7 月 1 日
I managed to get it to work.
The Code —
a = linspace(0, 2*pi, numel(r));
r = linspace(0,1,100);
[A,R] = ndgrid(a,r);
Z = (2*sqrt((R)/12)); % Calculate Curve
[X,Y,Z] = pol2cart(A,Z,R); % Set ‘Z’ As The Radius Matrix, ‘R’ Matrix As ‘Z’
figure
mesh(Z, Y, X, 'FaceAlpha',0.75)
grid on
axis('equal') % Avoid Scaling Distortion
hold on
plot3(xlim+[-0.1 0.1], [0 0], [0 0], 'k', 'LineWidth',2) % Centre Axis (If Needed)
hold off
The Plot —
I added a centre axis line just for fun, and set 'FaceAlpha' at less than 1 to make it visible. You can eliminate it by simply eliminating everything after the axis call.
Experiment to get different results.
This was a bit of a challenge!
MLP
MLP 2020 年 7 月 1 日
hey thank you so much for taking the time to help me out, it works perfectly!
Star Strider
Star Strider 2020 年 7 月 1 日
As always, my pleasure!

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

その他の回答 (1 件)

Gurpreet Singh
Gurpreet Singh 2020 年 6 月 30 日

0 投票

Hi Mateo,
It is my understanding that you are trying to create a 3D surface using a 2D plot by revolving it around the x axis.
The following links might help you.

カテゴリ

タグ

質問済み:

MLP
2020 年 6 月 30 日

コメント済み:

2020 年 7 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by