使用PyAEDT模組,適合簡單平面。
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 14 23:36:29 2022
@author: mlin
"""
from math import sqrt
from collections import defaultdict
from scipy import interpolate
from pyaedt import Hfss
hfss = Hfss(specified_version='2021.2')
x = hfss.modeler.object_list
path = x[1]
polygon = x[0]
ds = 0
s_map = {}
for edge in path.edges:
v1, v2 = edge.vertices
x1, y1, z1 = v1.position
x2, y2, z2 = v2.position
if len(s_map) == 0:
s_map[ds] = [(0, 0)]
ds += sqrt((x2 - x1) ** 2 + (z2 - z1) ** 2)
s_map[ds] = (x2, z2)
result = defaultdict(list)
for edge in polygon.edges:
v1, v2 = edge.vertices
x1, y1, z1 = v1.position
x2, y2, z2 = v2.position
x = [x1, x2]
y = [y1, y2]
f = interpolate.interp1d(x, y)
if x2 > x1:
new_s = [i for i in s_map.keys() if x2 >= i >= x1]
else:
new_s = [i for i in reversed(s_map.keys()) if x2 <= i <= x1]
print(new_s)
new_y = f(new_s)
for s, y3 in zip(new_s, new_y):
x3, z3 = s_map[s]
result[s].append((x3, y3, z3))
keys = [k for k in result]
pieces = []
for m, n in zip(keys[0:-1], keys[1:]):
v1, v2 = result[m][0:2]
v4, v3 = result[n][0:2]
p = hfss.modeler.primitives.create_polyline([v1, v2, v3, v4], cover_surface=True, close_surface=True)
pieces.append(p)
sheet = hfss.modeler.unite(pieces)
hfss.modeler.purge_history([pieces[0].name])