Python实现管线建模 - 偏心变径管、 弯头

news/2024/10/18 16:49:15/

偏心变径管

        偏心变径管是一种用于连接不同直径管道的管件,其特点是两端的中心线不在同一条直线上。偏心变径管常用于水平管道系统,以确保管道内部流体的平稳流动和避免积水。

        偏心变径管的一侧是平的,这使得两端的管道在一侧是对齐的,而另一侧存在高度差。这种结构设计使其在某些特定场景中具有独特的优势,如下图所示。

        应用场景

        水平管道系统:

        在水平管道中,使用偏心变径管可以避免积水或沉积物的堆积。平的一侧通常放置在下方,使液体流动顺畅,防止在变径处形成气袋。

        泵的入口和出口:

        在泵的入口使用偏心变径管,可以避免泵入口处的气穴现象。出口处使用偏心变径管,有助于保持流体压力的稳定。

        流体流动的平稳过渡:

        当管道系统中需要从大管径过渡到小管径时,偏心变径管可以提供平稳的流动过渡,减少流体阻力和压力损失。

将粗管和细管直接拼接在一起,构成最简单的

python">import trimesh
import numpy as npdef create_eccentric_reducer(diameter1=1.0, diameter2=0.5, height1=3.0, height2=2.0, offset=0.25):# 创建粗圆柱体cylinder1 = trimesh.creation.cylinder(radius=diameter1 / 2, height=height1, sections=32)cylinder1.apply_translation([0, 0, height1 / 2])# 创建细圆柱体cylinder2 = trimesh.creation.cylinder(radius=diameter2 / 2, height=height2, sections=32)cylinder2.apply_translation([offset, 0, height1 + height2 / 2])# 合并两个圆柱体combined_mesh = trimesh.util.concatenate([cylinder1, cylinder2])return combined_mesh# 创建偏心异径管
eccentric_reducer = create_eccentric_reducer()# 导出偏心异径管模型
eccentric_reducer.export('eccentric_reducer.obj')

不过这样把两个管直接拼在一起,效果很生硬、很不美观。。。

那么我们可以在两条管线之间增加一个过渡的锥体,用来实现平滑连接两条管线的效果。

python">import trimesh
import numpy as npdef create_smooth_eccentric_reducer(diameter1=1.0, diameter2=0.5, height1=2.0, height2=1.5, transition_length=1.0, offset=0.25):# 创建粗圆柱体cylinder1 = trimesh.creation.cylinder(radius=diameter1 / 2, height=height1, sections=32)cylinder1.apply_translation([0, 0, height1 / 2])# 创建细圆柱体cylinder2 = trimesh.creation.cylinder(radius=diameter2 / 2, height=height2, sections=32)cylinder2.apply_translation([offset, 0, height1 + transition_length + height2 / 2])# 创建过渡部分# 计算过渡部分的顶点angles = np.linspace(0, 2 * np.pi, 32)top_radius = diameter1 / 2bottom_radius = diameter2 / 2top_circle = np.column_stack((np.cos(angles) * top_radius, np.sin(angles) * top_radius, np.full(32, height1)))bottom_circle = np.column_stack((np.cos(angles) * bottom_radius + offset, np.sin(angles) * bottom_radius, np.full(32, height1 + transition_length)))# 创建过渡部分的面vertices = np.vstack((top_circle, bottom_circle))faces = []for i in range(31):faces.append([i, i + 1, 32 + i + 1])faces.append([i, 32 + i + 1, 32 + i])faces.append([31, 0, 32])  # 闭合环形部分faces.append([31, 32, 63])transition_mesh = trimesh.Trimesh(vertices=vertices, faces=faces)# 组合所有部分combined_mesh = trimesh.util.concatenate([cylinder1, transition_mesh, cylinder2])return combined_mesh# 创建偏心变径管
eccentric_reducer = create_smooth_eccentric_reducer()# 导出模型
eccentric_reducer.export('smooth_eccentric_reducer.obj')

弯  头

        管线弯头(转折)管道系统中用于改变流体流动方向的重要连接件。它们通常用于管道拐弯处的连接,使管道能够按照所需的角度进行转弯。

        我们可以用两条管线拼接的方式来简单地表示一个弯头:

python">
import trimesh
import numpy as np# 简单转折
def create_cylinder_between_points(start, end, radius, sections=32):# 计算长度和方向vector = np.array(end) - np.array(start)length = np.linalg.norm(vector)direction = vector / length# 创建圆柱体cylinder = trimesh.creation.cylinder(radius=radius, height=length, sections=sections)# 计算旋转矩阵z_axis = np.array([0, 0, 1])rotation_axis = np.cross(z_axis, direction)rotation_angle = np.arccos(np.dot(z_axis, direction))rotation_matrix = trimesh.transformations.rotation_matrix(rotation_angle, rotation_axis)# 应用旋转和平移cylinder.apply_transform(rotation_matrix)cylinder.apply_translation(start + vector / 2)return cylinderdef create_elbow_fitting():# 定义管线的起终点坐标和管径start_A, end_A = [0, 0, 0], [1, 0, 0]  # 管线Astart_B, end_B = [1, 0, 0], [1, 1, 0]  # 管线Bradius_A = 0.5 / 2radius_B = 0.5 / 2# 分别创建管线cylinder_A = create_cylinder_between_points(start_A, end_A, radius_A)cylinder_B = create_cylinder_between_points(start_B, end_B, radius_B)# 组合管线elbow_fitting = trimesh.util.concatenate([cylinder_A, cylinder_B])return elbow_fitting# 创建转折模型
elbow_fitting = create_elbow_fitting()# 可视化模型
elbow_fitting.show()# 导出模型
elbow_fitting.export('wantou1.obj')

        不过这种表示方法的缺点很明显,管线转折处会有明显的缝隙。

        我们可以给转折点填充一个球体(球体直径 = 管线管径),用来避免转折点的缝隙:

python">import trimesh
import numpy as np# 90°转折+球填充
def create_cylinder_between_points(start, end, radius, sections=32):# 计算长度和方向vector = np.array(end) - np.array(start)length = np.linalg.norm(vector)direction = vector / length# 创建圆柱体cylinder = trimesh.creation.cylinder(radius=radius, height=length, sections=sections)# 计算旋转矩阵z_axis = np.array([0, 0, 1])rotation_axis = np.cross(z_axis, direction)rotation_angle = np.arccos(np.dot(z_axis, direction))rotation_matrix = trimesh.transformations.rotation_matrix(rotation_angle, rotation_axis)# 应用旋转和平移cylinder.apply_transform(rotation_matrix)cylinder.apply_translation(start + vector / 2)return cylinderdef create_elbow_fitting():# 定义管线的起终点坐标和管径start_A, end_A = [0, 0, 0], [1, 0, 0]  # 管线Astart_B, end_B = [1, 0, 0], [1, 1, 0]  # 管线Bradius_A = 0.5 / 2radius_B = 0.5 / 2# 创建直管部分cylinder_A = create_cylinder_between_points(start_A, end_A, radius_A)cylinder_B = create_cylinder_between_points(start_B, end_B, radius_B)# 创建球体来填补转折处的缝隙sphere_radius = max(radius_A, radius_B)sphere = trimesh.creation.icosphere(subdivisions=3, radius=sphere_radius)sphere.apply_translation([1, 0, 0])# 组合所有部分elbow_fitting = trimesh.util.concatenate([cylinder_A, sphere, cylinder_B])return elbow_fitting# 创建转折模型
elbow_fitting = create_elbow_fitting()# 可视化模型
elbow_fitting.show()# 导出模型
elbow_fitting.export('wantou2.obj')


http://www.ppmy.cn/news/1474461.html

相关文章

低代码开发在金融系统中的应用研究

低代码开发在金融系统中的实施策略 在金融行业,系统的稳定性、安全性以及数据的完整性是至关重要的考虑要素。因此,低代码开发策略在金融系统中的应用必须遵循一系列精细且严格的实施准则。 明确且精准的业务需求分析是基础。金融系统的复杂性意味着在开…

k8s集群部署mysql8主备

一、搜索mysql8版本 # helm search repo mysql# helm pull bitnami/mysql --version:11.1.2# tar -zxf mysql-11.1.2.tgz# cd mysql 二、修改value.ysqml文件 动态存储类自己提前搭建。 # helm install mysql8 -n mysql-cluster ./ -f values.yaml NAME: mysql8 LAST DEPLOYED…

Linux文件编程(标准C库)

目录 一、标准C库打开/创建文件,读写文件,光标移动 二、标准C库写入结构体到文件 三、其他函数补充 1.fputc函数 2.feof函数和fgetc函数 前面讲到的open函数都是基于linux内核的,也就是说在Windows系统上无法运行,移植性比较…

数据编码的艺术:sklearn中的数据转换秘籍

数据编码的艺术:sklearn中的数据转换秘籍 在机器学习中,数据预处理是一个至关重要的步骤,它直接影响到模型的性能和结果的准确性。数据编码转换是数据预处理的一部分,它涉及将原始数据转换成适合模型训练的格式。scikit-learn&am…

LeetCode HOT100(三)滑动窗口

子数组最大平均数 I (非hot100,但是滑动窗口的思想可以很好的体现,入门滑动窗口很好的题) 给你一个由 n 个元素组成的整数数组 nums 和一个整数 k 。 请你找出平均数最大且 长度为 k 的连续子数组,并输出该最大平均数…

外科休克病人的护理

一、引言 休克是外科常见的危急重症之一,它是由于机体遭受强烈的致病因素侵袭后,有效循环血量锐减、组织灌注不足所引起的以微循环障碍、细胞代谢紊乱和器官功能受损为特征的综合征。对于外科休克病人的护理,至关重要。 二、休克的分类 外科休克主要分为低血容量性休克(包括…

SpringMVC源码解析(一):web容器启动流程

SpringMVC源码系列文章 SpringMVC源码解析(一):web容器启动流程 目录 一、SpringMVC全注解配置1、pom文件2、web容器初始化类(代替web.xml)3、SpringMVC配置类(代替springmvc.xml)4、测试Controller 二、SpringServletContainerInitializer1、web容器初始化入口2、…

防火墙安全策略用户认证综合实验

目录 一、实验题目要求 二、拓扑搭建,IP地址规划 三、二层配置 1.配置IP地址 2.VLAN配置 四、三层的配置(防火墙配置) 1.IP地址配置 2.云配置 3.在浏览器上使用https协议登陆防火墙 (1)配置对应dmz区的G1/0/0…