codextrapezoidal-wing-reference-chord.py
trapezoidal-wing-reference-chord.py
"""Equal chord distributions with distinct swept reference placement; PNG in cwd."""
from pathlib import Path
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
def main():
b,cr,ct,xroot=10.,2.,1.,.1
lam=ct/cr;area=b*(cr+ct)/2
mac=2*cr/3*(1+lam+lam**2)/(1+lam)
ymac=b/6*(1+2*lam)/(1+lam)
y=np.linspace(0,b/2,10001);chord=cr-(cr-ct)*2*y/b
np.testing.assert_allclose(2*np.trapezoid(chord,y),area)
np.testing.assert_allclose(2*np.trapezoid(y*chord,y)/area,ymac,atol=1e-8)
np.testing.assert_allclose(2*np.trapezoid(chord**2,y)/area,mac,atol=1e-8)
assert np.isclose(mac,14/9)
fig,axes=plt.subplots(1,2,figsize=(9.6,4.2),dpi=100,facecolor='white')
quarters=[]
for ax,sweep in zip(axes,[0.,20.]):
tangent=np.tan(np.radians(sweep));leading=xroot+y*tangent
reference=xroot+ymac*tangent
np.testing.assert_allclose(2*np.trapezoid(leading*chord,y)/area,reference,atol=1e-8)
quarters.append(reference+mac/4)
ax.add_patch(Polygon([(0,xroot),(5,xroot+5*tangent),(5,xroot+5*tangent+ct),(0,xroot+cr)],facecolor='#deedf7',edgecolor='#2475ad',lw=2))
ax.plot([ymac,ymac],[reference,reference+mac],color='#b43f32',lw=3,label='Mean-chord reference segment')
ax.scatter([ymac],[reference+mac/4],color='#b43f32',s=35,zorder=3,label='Geometric quarter-chord reference')
ax.set(xlim=(-.25,5.25),ylim=(3.3,-.2),xlabel='Half-span coordinate y (m)',ylabel='Chordwise coordinate x (m)',title=f'Leading-edge sweep {sweep:.0f}°')
ax.set_aspect('equal',adjustable='box');ax.grid(alpha=.2)
ax.text(.15,3.05,f'MAC length = {mac:.4f} m',fontsize=10)
np.testing.assert_allclose(quarters[1],1.2977116317026718)
np.testing.assert_allclose(quarters[1]-quarters[0],ymac*np.tan(np.radians(20)))
handles,labels=axes[0].get_legend_handles_labels()
fig.legend(handles,labels,loc='lower center',ncol=2,fontsize=9)
fig.suptitle('Same span, root and tip chords; different reference positions',fontsize=12)
fig.tight_layout(rect=(0,.17,1,.94))
fig.savefig(Path.cwd()/(Path(__file__).stem+'.png'),facecolor='white');plt.close(fig)
if __name__=='__main__':main()