フィルターのクリア

how can i convert 2d plot in to 3d surface ??

9 ビュー (過去 30 日間)
Dr Sohaib Khan
Dr Sohaib Khan 2024 年 4 月 25 日
コメント済み: Dr Sohaib Khan 2024 年 4 月 28 日
I have this small code that plots ogive shape nose in 2d.
I want to develop 3d surface from this code !!! please help and guide....
I am using surf command and tried to turn vector in to matrix....
L = 500;
R = 79;
n= 0.4;
x = 0:0.01:50;
y= R*(x/L).^n;
z= 1.*(x/L).^n;
plot(x,y,'r','linewidth',2)
hold on
plot(x,-y,'r','linewidth',2)
xlabel('Length')
ylabel('Radius')
title('Nose Profile')
axis('equal');
  5 件のコメント
VBBV
VBBV 2024 年 4 月 26 日
@Dr Sohaib Khan, As @Walter Roberson & @John D'Errico mentioned you could create multple surfaces depending on the which dimension is taken to rotate the 2D line plot. Since you dont want to change L, R, & n, you can use commands like surf or mesh as shown below
L = 500;
R = 79;
n= 0.4;
x = 0:0.01:50;
y = R*(x/L).^n;
z = 1.*(x/L).^n;
[X, Th] = meshgrid(linspace(1,50,100),linspace(0,2*pi,100));
Y = (R*(X/L).^n).*cos(Th);
Z = (1.*(X/L).^n).*sin(Th);
subplot(211)
plot(x,y,'r','linewidth',2)
hold on
plot(x,-y,'r','linewidth',2)
xlabel('Length')
ylabel('Radius')
title('Nose Profile')
axis([-10 50 -40 40]);
subplot(212)
s=surf(X,Y,Z);shading interp;view([30 15])
Dr Sohaib Khan
Dr Sohaib Khan 2024 年 4 月 28 日
Thankyou soooo much VBBV !!!! :) :) :)

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

採用された回答

Rohit Kulkarni
Rohit Kulkarni 2024 年 4 月 25 日
編集済み: Rohit Kulkarni 2024 年 4 月 25 日
Hi Sohaib,
In my understanding you want to develop a 3D surface from your 2D ogive shape nose profile, in order to do this we use the surf command. Here we create a meshgrid that represents domain for your surface and then compute the corresponding z-values using your ogive formula.
Here is the code:
L = 500;
R = 79;
n= 0.4;
x = 0:0.01:50;
y= R*(x/L).^n;
z= 1.*(x/L).^n;
plot(x,y,'r','linewidth',2)
hold on
plot(x,-y,'r','linewidth',2)
xlabel('Length')
ylabel('Radius')
title('Nose Profile')
axis('equal');
L = 500;
R = 79;
n = 0.4;
x = linspace(0, 50, 500); % Define x over the desired range with more points for smoothness
theta = linspace(0, 2*pi, 500); % Define theta for a full circle (360 degrees)
[X, Theta] = meshgrid(x, theta); % Create a meshgrid for X and Theta
% Calculate the radius (y) for each x using the ogive formula
Y = R * (X/L).^n;
% Convert polar coordinates (r, theta) to Cartesian coordinates (Y, Z) for plotting
Y = Y .* cos(Theta); % Y component
Z = Y .* sin(Theta); % Z component, using the same radius to maintain the profile shape
% Plot the 3D surface
surf(X, Y, Z, 'EdgeColor', 'none') % Use 'none' to remove gridlines for a smoother appearance
xlabel('Length')
ylabel('Radius')
zlabel('Height')
title('3D Ogive Shape')
axis equal % Use 'axis equal' to maintain aspect ratio
Refer to the following links for the documentation of the functions used above:
Hope this helps!
  1 件のコメント
Dr Sohaib Khan
Dr Sohaib Khan 2024 年 4 月 28 日
Thank you rohit !!!! much appreciated :) :) :) regards

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by