how to convert 2D graph to 3D?
38 views (last 30 days)
Show older comments
oussama souadka
on 20 Nov 2016
Commented: Anh Phan Viet
on 16 Mar 2020
I writed a code that can give us a 2D wing airfoil with specific number points and coordinations of each one, is there any example or documentations about making my airfoil 3D by only extending it or by controlling the projection of it
3 Comments
Accepted Answer
Star Strider
on 20 Nov 2016
Edited: Star Strider
on 20 Nov 2016
I don’t have your wing section or your code creating it, so I created something that resembles it (the (2xN) ‘y’ matrix has the upper wing profile in the first row and the lower wing profile in the second row), then did the plot:
x = linspace(0, 1, 100); % Create Data (Independent Variable)
y = [x.*exp(-8.0*x); -x.*exp(-8.0*x)]; % Create Data (Dependent Variable Matrix)
figure(1)
plot(x, y) % 2-D Wing Section
grid
figure(2)
surf([x; x], [y(1,:); y(1,:)], [zeros(size(x)); ones(size(x))]) % Upper Half Of 3-D Wing Section
hold on
surf([x; x], [y(2,:); y(2,:)], [zeros(size(x)); ones(size(x))]) % Lower Half Of 3-D Wing Section
hold off
grid on
The Plot —
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/175592/image.png)
You will have to adapt this to your own code, but it should not be difficult. You simply have to put your wing profiles in the rows of the ‘y’ matrix, and use the ‘x’ you used to plot your 2-D plot as the independent variable.
(I admit to a bit of cheating. I looked at the way the cylinder function creates its cylinder, then adapted that idea to plot your wing section.)
EDIT —
I found some code for a NACA airfoil, so adapted my earlier code to it. The airfoil is plotted horizontally in figure(2). Note the rotate calls after the plot.
Airfoil Code (Archive) —
c=1; %chord length
s=num2str(2412);
NACA=s; %4 digits
d1=str2double(s(1)); % pulls the first digit out of the scalar
d2=str2double(s(2));% pulls the second digit out of the scalar
d34=str2double(s(3:4)); % pulls the third and fourth digit out of the scalar
m=d1/100;
p=d2/10;
t=d34/100;
x=linspace(0, c, 250);
yt =5*t*c*(.2969*(sqrt(x/c))+-.1260*(x/c)+-.3516*(x/c).^2+.2843*(x/c).^3+-.1015*(x/c).^4);
for k = 1:length(x)
if x(k) <= p*c
yc(k)=m*(x(k)/p^2)*(2*p-(x(k)/c));
dx(k)=(2*m)/p^2*(p-(x(k)/c));
elseif x(k) > p*c
yc(k)=m*((c-x(k))/(1-p)^2)*(1+(x(k)/c)-(2*p));
dx(k)=((2*m)/(1-p)^2)*(p-(x(k)/c));
end
%upper and lower limits of the airfoil (xu,yu) ; (xl,yl)
theta=atan(dx(k));
xu(k)=x(k)-yt(k)*sin(theta);
yu(k)=yc(k)+yt(k)*cos(theta);
xl(k)=x(k)+yt(k)*sin(theta);
yl(k)=yc(k)-yt(k)*cos(theta);
end
%plot of airfoil
plot(xu,yu)
hold on
plot(xl,yl,'r')
plot(x,yc,'g')
axis equal
grid
figure(2)
hu = mesh([xu; xu], [yu; yu], [zeros(size(xu)); ones(size(xu))]); % Upper Half Of 3-D Wing Section
hold on
hl = mesh([xl; xl], [yl; yl], [zeros(size(xl)); ones(size(xl))]); % Lower Half Of 3-D Wing Section
hold off
grid on
axis([0 1 -0.4 0.4 0 1])
rotate(hu,[1 0 0], 90)
rotate(hl,[1 0 0], 90)
title('NACA 2412 Airfoil')
The Second Plot —
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/175595/image.png)
8 Comments
More Answers (0)
See Also
Categories
Find more on Airfoil tools 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!