# -*- coding:utf-8 -*-# Explanations for this script can be found at# http://pythonocc.wordpress.com/2013/04/01/using-external-airfoil-data-to-create-a-solid-wing/#import ssl
import urllib.request as urllib2
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeFace
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakePrism
from OCC.Core.Geom2dAPI import Geom2dAPI_PointsToBSpline
from OCC.Core.GeomAPI import geomapi
from OCC.Core.gp import gp_Pnt, gp_Vec, gp_Pnt2d, gp_Pln, gp_Dir
from OCC.Core.TColgp import TColgp_Array1OfPnt2d
from OCC.Display.SimpleGui import init_display
from OCC.Extend.ShapeFactory import make_wire, make_edge
classUiucAirfoil(object):"""
Airfoil with a section from the UIUC database
"""def__init__(self, chord, span, profile):
self.chord = chord #弦
self.span = span #跨度
self.profile = profile #简介
self.shape = self.make_shape()defmake_shape(self):# 1 - retrieve the data from the UIUC airfoil data page# 1 -从UIUC翼型数据页面检索数据
foil_dat_url ='http://m-selig.ae.illinois.edu/ads/coord_seligFmt/%s.dat'% self.profile
# http://m-selig.ae.illinois.edu/ads/coord_seligFmt/b737a.dat# explicitly tell to not use ssl verification #明确告诉不要使用ssl验证
ssl._create_default_https_context = ssl._create_unverified_context
print("Connecting to m-selig, retrieving foil data")
f = urllib2.urlopen(foil_dat_url)print("Building foil geometry")
plan = gp_Pln(gp_Pnt(0.,0.,0.), gp_Dir(0.,0.,1.))# Z=0 plan / XY plan
section_pts_2d =[]#空数组for line in f.readlines()[1:]:# 2# The first line contains info only do some cleanup on the data (mostly dealing with spaces)# 2# 第一行包含的信息只是对数据做一些清理(主要是处理空格)
data = line.split()#分 割线# 3 - create an array of points # 3 -创建一组点iflen(data)==2:# two coordinates for each point #每个点两个坐标
section_pts_2d.append(gp_Pnt2d(float(data[0])*self.chord,#chord=500float(data[1])*self.chord))# 4 - use the array to create a spline describing the airfoil section # 4 -使用数组创建描述翼型截面的样条曲线
spline_2d = Geom2dAPI_PointsToBSpline(point2d_list_to_TColgp_Array1OfPnt2d(section_pts_2d),len(section_pts_2d)-1,# order min #最小顺序len(section_pts_2d))# order max #最大顺序
spline = geomapi.To3d(spline_2d.Curve(), plan)# 5 - figure out if the trailing edge has a thickness or not and create a Face,-弄清楚后缘是否有厚度, 创建一张脸try:#first and last point of spline -> trailing edge# 样条曲线的第一点和最后一点->后缘,将第一点与最后一点相连通,形成闭合
trailing_edge = make_edge(gp_Pnt(section_pts_2d[0].X(), section_pts_2d[0].Y(),0.0),
gp_Pnt(section_pts_2d[-1].X(), section_pts_2d[-1].Y(),0.0))
face = BRepBuilderAPI_MakeFace(make_wire([make_edge(spline), trailing_edge]))except AssertionError:# the trailing edge segment could not be created, probably because# the points are too close # 无法创建后缘段,可能是因为# 这些点太接近了# No need to build a trailing edge# 不需要建立后缘
face = BRepBuilderAPI_MakeFace(make_wire(make_edge(spline)))# 6 - extrude the Face to create a Solid # 6 -挤出面以创建实体return BRepPrimAPI_MakePrism(face.Face(),
gp_Vec(gp_Pnt(0.,0.,0.),
gp_Pnt(0.,0., self.span))).Shape()#span跨度defpoint2d_list_to_TColgp_Array1OfPnt2d(li):"""
List of gp_Pnt2d to TColgp_Array1OfPnt2d
"""return _Tcol_dim_1(li, TColgp_Array1OfPnt2d)def_Tcol_dim_1(li, _type):"""
Function factory for 1-dimensional TCol* types
"""
pts = _type(0,len(li)-1)for n, i inenumerate(li):
pts.SetValue(n, i)return pts
if __name__ =='__main__':
airfoil = UiucAirfoil(50.,200.,'b737a')
display, start_display, add_menu, add_function_to_menu = init_display()
display.DisplayShape(airfoil.shape, update=True)
start_display()
BOEING 737 ROOT AIRFOIL
1.0000000.0003000.9109000.0132000.8351000.0224000.6488000.0498000.5965000.0575000.5593000.0626000.5034000.0696000.4477000.0756000.3919000.0804000.3520000.0833000.3094000.0858000.2504000.0887000.1961000.0905000.1530000.0907000.0990000.0866000.0740000.0814000.0495000.0730000.0249000.0582000.0143000.0499000.0076000.0415000.0050000.0372000.0023000.0309000.0000000.0177000.0022000.0038000.004900-0.0018000.007200-0.0053000.011900-0.0106000.024300-0.0204000.048600-0.0342000.071600-0.0457000.097900-0.0516000.148800-0.0607000.195300-0.0632000.250100-0.0632000.294500-0.0626000.357900-0.0610000.396500-0.0595000.454300-0.0563000.505000-0.0527000.555600-0.0482000.606300-0.0427000.648500-0.0375000.831700-0.0149000.941000-0.0053001.000000-0.000300