pythonocc_文件_数组_界面_体积

在这里插入图片描述

# -*- 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

class UiucAirfoil(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()

    def make_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 -创建一组点
            if len(data) == 2:  # two coordinates for each point #每个点两个坐标
                section_pts_2d.append(gp_Pnt2d(float(data[0])*self.chord,  #chord=500
                                               float(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跨度


def point2d_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 in enumerate(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.000000 0.000300
0.910900 0.013200
0.835100 0.022400
0.648800 0.049800
0.596500 0.057500
0.559300 0.062600
0.503400 0.069600
0.447700 0.075600
0.391900 0.080400
0.352000 0.083300
0.309400 0.085800
0.250400 0.088700
0.196100 0.090500
0.153000 0.090700
0.099000 0.086600
0.074000 0.081400
0.049500 0.073000
0.024900 0.058200
0.014300 0.049900
0.007600 0.041500
0.005000 0.037200
0.002300 0.030900
0.000000 0.017700
0.002200 0.003800
0.004900 -0.001800
0.007200 -0.005300
0.011900 -0.010600
0.024300 -0.020400
0.048600 -0.034200
0.071600 -0.045700
0.097900 -0.051600
0.148800 -0.060700
0.195300 -0.063200
0.250100 -0.063200
0.294500 -0.062600
0.357900 -0.061000
0.396500 -0.059500
0.454300 -0.056300
0.505000 -0.052700
0.555600 -0.048200
0.606300 -0.042700
0.648500 -0.037500
0.831700 -0.014900
0.941000 -0.005300
1.000000 -0.000300
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值