I’m trying to plot an airfoil from the formula as described on this wikipedia page.
This Jupyter notebook can be viewed on this github page.
JavaScript
x
62
62
1
%matplotlib inline
2
import math
3
import matplotlib.pyplot as pyplot
4
5
def frange( start, stop, step ):
6
yield start
7
while start <= stop:
8
start += step
9
yield start
10
11
#https://en.wikipedia.org/wiki/NACA_airfoil#Equation_for_a_cambered_4-digit_NACA_airfoil
12
def camber_line( x, m, p, c ):
13
if 0 <= x <= c * p:
14
yc = m * (x / math.pow(p,2)) * (2 * p - (x / c))
15
#elif p * c <= x <= c:
16
else:
17
yc = m * ((c - x) / math.pow(1-p,2)) * (1 + (x / c) - 2 * p )
18
return yc
19
20
def dyc_over_dx( x, m, p, c ):
21
if 0 <= x <= c * p:
22
dyc_dx = ((2 * m) / math.pow(p,2)) * (p - x / c)
23
#elif p * c <= x <= c:
24
else:
25
dyc_dx = ((2 * m ) / math.pow(1-p,2)) * (p - x / c )
26
return dyc_dx
27
28
def thickness( x, t, c ):
29
term1 = 0.2969 * (math.sqrt(x/c))
30
term2 = -0.1260 * (x/c)
31
term3 = -0.3516 * math.pow(x/c,2)
32
term4 = 0.2843 * math.pow(x/c,3)
33
term5 = -0.1015 * math.pow(x/c,4)
34
return 5 * t * c * (term1 + term2 + term3 + term4 + term5)
35
36
def naca4( m, p, t, c=1 ):
37
for x in frange( 0, 1.0, 0.01 ):
38
dyc_dx = dyc_over_dx( x, m, p, c )
39
th = math.atan( dyc_dx )
40
yt = thickness( x, t, c )
41
yc = camber_line( x, m, p, c )
42
xu = x - yt * math.sin(th)
43
xl = x + yt * math.sin(th)
44
yu = yc + yt * math.cos(th)
45
yl = yc - yt * math.cos(th)
46
yield (xu, yu), (xl, yl)
47
48
#naca2412
49
m = 0.02
50
p = 0.4
51
t = 12
52
53
naca4points = naca4( m, p, t )
54
for (xu,yu),(xl,yl) in naca4points:
55
pyplot.plot( xu, yu, 'r,')
56
pyplot.plot( xl, yl, 'r,')
57
pyplot.ylabel('y')
58
pyplot.xlabel('x')
59
pyplot.axis('equal')
60
figure = pyplot.gcf()
61
figure.set_size_inches(16,16,forward=True)
62
I expected it to look more like .
Questions: Why is the line not completely smooth? There seems to be a discontinuity where the beginning and end meet. Why does it not look like the diagram on wikipedia? How do I remove the extra loop at the trailing edge? How do I fix the chord so that it runs from 0.0 to 1.0?
Advertisement
Answer
First, t
should be 0.12
not 12
. Second, to make a smoother plot, increase the sample points.
It is also a good idea to use vectorize method in numpy
:
JavaScript
1
48
48
1
%matplotlib inline
2
import math
3
import matplotlib.pyplot as plt
4
import numpy as np
5
6
#https://en.wikipedia.org/wiki/NACA_airfoil#Equation_for_a_cambered_4-digit_NACA_airfoil
7
def camber_line( x, m, p, c ):
8
return np.where((x>=0)&(x<=(c*p)),
9
m * (x / np.power(p,2)) * (2.0 * p - (x / c)),
10
m * ((c - x) / np.power(1-p,2)) * (1.0 + (x / c) - 2.0 * p ))
11
12
def dyc_over_dx( x, m, p, c ):
13
return np.where((x>=0)&(x<=(c*p)),
14
((2.0 * m) / np.power(p,2)) * (p - x / c),
15
((2.0 * m ) / np.power(1-p,2)) * (p - x / c ))
16
17
def thickness( x, t, c ):
18
term1 = 0.2969 * (np.sqrt(x/c))
19
term2 = -0.1260 * (x/c)
20
term3 = -0.3516 * np.power(x/c,2)
21
term4 = 0.2843 * np.power(x/c,3)
22
term5 = -0.1015 * np.power(x/c,4)
23
return 5 * t * c * (term1 + term2 + term3 + term4 + term5)
24
25
def naca4(x, m, p, t, c=1):
26
dyc_dx = dyc_over_dx(x, m, p, c)
27
th = np.arctan(dyc_dx)
28
yt = thickness(x, t, c)
29
yc = camber_line(x, m, p, c)
30
return ((x - yt*np.sin(th), yc + yt*np.cos(th)),
31
(x + yt*np.sin(th), yc - yt*np.cos(th)))
32
33
34
#naca2412
35
m = 0.02
36
p = 0.4
37
t = 0.12
38
c = 1.0
39
40
x = np.linspace(0,1,200)
41
for item in naca4(x, m, p, t, c):
42
plt.plot(item[0], item[1], 'b')
43
44
plt.plot(x, camber_line(x, m, p, c), 'r')
45
plt.axis('equal')
46
plt.xlim((-0.05, 1.05))
47
# figure.set_size_inches(16,16,forward=True)
48