how to convert 2D graph to 3D?

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

You want thickness same every where?
yes exactly, and if the is any possibility to change the projection. like if i create 2 different airfoils one in Z=0 and the other Z=x for example can i connect them ??
Yes can be connected...how you want it?

Sign in to comment.

 Accepted Answer

Star Strider
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
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

8 Comments

Thank u very much mate, you are a hero.
My pleasure!
This was an interesting problem!
Mr. Star Strider, i have some difficulties to do the same to my code, i believe because of i made x and y as [Coord] and have no idea how to change it, can you plz spare some time by looking at it.
Your files do not work for me. I have no idea what you are doing, how you design your airfoil, or calculate its profile coordinates.
Thank u any way sir
My pleasure.
It should be relatively easy for you to insert my code for ‘figure(2)’ in my revised (edited) code into your code. The ‘xu’ and ‘yu’ values are the coordinates of the upper surface of your airfoil, and ‘xl’ and ‘yl’ for the lower surface. (Note that my code assumes row vectors for these.) All you need to do is to assign those names to the corresponding vectors from your airfoil calculations and then plot them using the code in ‘figure(2)’. My code does everything else.
For example:
xu = your_x_vector_for_the_upper_surface;
yu = your_y_vector_for_the_upper_surface;
xl = your_x_vector_for_the_lower_surface;
yl = your_y_vector_for_the_lower_surface;
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( '...' ) % Insert Appropriate Title
Use the sprintf function to change the title for different airfoil labels:
title(sprintf('Airfoil Name: %s', Airfoil_Name))
How would you find the volume within the surf plot?
Excuse me, how can I fill your first 3D image with colour inside?

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!