Filter löschen
Filter löschen

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

5 Ansichten (letzte 30 Tage)
Dr Sohaib Khan
Dr Sohaib Khan am 25 Apr. 2024
Kommentiert: Dr Sohaib Khan am 28 Apr. 2024
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 Kommentare
VBBV
VBBV am 26 Apr. 2024
@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 am 28 Apr. 2024
Thankyou soooo much VBBV !!!! :) :) :)

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Rohit Kulkarni
Rohit Kulkarni am 25 Apr. 2024
Bearbeitet: Rohit Kulkarni am 25 Apr. 2024
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 Kommentar
Dr Sohaib Khan
Dr Sohaib Khan am 28 Apr. 2024
Thank you rohit !!!! much appreciated :) :) :) regards

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by