生成PDMS管口方位图 python方案

本文介绍了一种用Python3的ezdxf模块,根据PDMS导出的管嘴信息来创建.dXF图形的方法。作者在现有方案基础上增加了针对实际案例的管嘴绘制细节。
摘要由CSDN通过智能技术生成

生成PDMS管口方位图 python方案

思路:通过python3的ezdxf模块,将pdms导出的管嘴信息生成.dxf图,网上已有初步方案(见参考),本文章主要增加以实际案例绘制管嘴部分内容。

一、代码
import math  # 导入math模块
import ezdxf  # 导入ezdxf模块


# 定义点的函数
class Point:
    def __init__(self, x=0, y=0):
        self.x = x
        self.y = y

    def getx(self):
        return self.x

    def gety(self):
        return self.y

    def getAxis(self):
        return (self.x, self.y)

# 定义直线函数
class Getlen:
    def __init__(self, p1, p2):
        self.x = p1.getx() - p2.getx()
        self.y = p1.gety() - p2.gety()
        # 用math.sqrt()求平方根
        self.len = math.sqrt((self.x ** 2) + (self.y ** 2))

    # 定义得到直线长度的函数
    def getlen(self):
        return self.len

# 通过矩形中心点p, 与x轴弧度,获取矩形四点坐标
def recLoc(p, angle, height, bottom):
    # assert angle <= 35, 'angle out of index'
    # angle *= (10 / 180) * math.pi  # 弧度

    # xo = np.cos(angle)
    # yo = np.sin(angle)
    xo = math.cos(angle)
    yo = math.sin(angle)

    y1 = p.x + height / 2 * yo
    x1 = p.y - height / 2 * xo
    y2 = p.x - height / 2 * yo
    x2 = p.y + height / 2 * xo

    return [
            Point(y1 - bottom / 2 * xo, x1 - bottom / 2 * yo),
            Point(y2 - bottom / 2 * xo, x2 - bottom / 2 * yo),
            Point(y2 + bottom / 2 * xo, x2 + bottom / 2 * yo),
            Point(y1 + bottom / 2 * xo, x1 + bottom / 2 * yo)
    ]

# 管口朝向转为角度,包含('W','E 30 S')两种格式
def getNozzAngle(s):
    arr = s.split(' ')
    phasJson = {
   'E': (0, 1),
                'N': (90, 2),
                'W': (180, 3),
                'S': (270, 4)}
    try:
        angle = float(phasJson[arr[0]][0])
        cursor = 1 if phasJson[arr[2]][1] > phasJson[arr[0]][1] else -1
        if arr[0] == 'E' and arr[2] == 'S':
            cursor = -1
        angle += cursor * float(arr[1])
        return (angle if angle > 0 else 360 + angle, True)
    except (KeyError, IndexError) as e:
        return (phasJson[arr[0]][0], False)

# *求圆和直线之间的交点
# *直线方程:y = kx + b
# *圆的方程:(x - m)² + (x - n)² = r²
# *x1, y1 = 线坐标1, x2, y2 = 线坐标2, m, n = 圆坐标, r = 半径
def getPointBeCircleAndLine(k, b, m, n, r):
    aX = 1 + k * k
    bX = 2 * k * 
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值