how can i convert 2d plot in to 3d surface ??
32 views (last 30 days)
Show older comments
Dr Sohaib Khan
on 25 Apr 2024
Commented: Dr Sohaib Khan
on 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 Comments
VBBV
on 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])
Accepted Answer
Rohit Kulkarni
on 25 Apr 2024
Edited: Rohit Kulkarni
on 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!
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!