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

조회 수: 34 (최근 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 CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by