在开发双尖拱的实体创建脚本开发中,想通过沿着世界坐标系x轴方向的若干平行的卵圆曲线(yoz平面上)放样生成,但遇到了问题:在rs.AddLoftSrf()中的object_ids ({guid, guid, …]): ordered list of the curves to loft through不支持Rhino.Geometry.Line生成的curves,请问大神,该如何进行后续放样形成实体??
脚本如下:
# -*- coding:UTF-8 -*-
from array import array
str_parameters_file = 'Arch.json'
import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
import sys
import json
import System
import math
sys.path.append('..\网格添加参数和表面网格化')
from addpara import addpara
from wanggehua import wanggehua
# 双尖拱形线平面方程
def CubicArchFunction(x, phi, d=9.936): # d:inch 与m 的转化关系
point = [0, 0, 0]
x = x / d # 转化为英寸
phi = math.radians(phi) # 角度转化为弧度
if -2.5 <= x < 0:
th = math.sin(math.radians(46.6)) ** 2
gx = math.sqrt(1 - th * (x / 2.5) ** 2) - math.cos(math.radians(46.6))
y = gx * math.cos(phi) / (1 - math.cos(math.radians(46.6)))
z = gx * math.sin(phi) / (1 - math.cos(math.radians(46.6)))
point[0] = x * d
point[1] = y * d
point[2] = z * d
if 0 <= x <= 5:
th = math.sin(math.radians(22.62)) ** 2
gx = math.sqrt(1 - th * (x / 5) ** 2) - math.cos(math.radians(22.62))
y = gx * math.cos(phi) / (1 - math.cos(math.radians(22.62)))
z = gx * math.sin(phi) / (1 - math.cos(math.radians(22.62)))
point[0] = x * d
point[1] = y * d
point[2] = z * d
return point
# 点列表转为3d点结构
def listtopointed(center):
center = Rhino.Geometry.Point3d(center[0], center[1], center[2])
return center
# 离散x轴,生成x点离散列表,点个数表,和归一化点个数表,为放样函数提供列表
def creat_crt_point(a, b, step, d=9.936):
a = a * d
b = b * d
lenth = int((a - b) / step) + 1
num = list(range(lenth))
reslut = [0, 1, 2]
numguiyihua = num[:]
numx = num[:]
for x in num:
numguiyihua[x] = num[x] / (len(num) - 1)
numx[x] = num[x] * step + b
reslut[0] = num
reslut[1] = numx
reslut[2] = numguiyihua
return reslut
def creat_phi_points(a, b, step, ): # 创造-pi~pi的点列表
results = range(a, b, step)
# RHI = results[:]
# for i in range(len(results)):
# RHI[i] = math.radians(results[i])
return results
def AddArch(str_path):
"""
已知Arch的宽、高、半径这三个特征参数,
创建AddArch的mesh结构,生成AddArch.3dm
=============== =================================================================
**参数**
*str_path* (str)几何模型参数json文件路径 如:str_parameters_file='**.json'
**返回值**
*Rhino.Commands.Result.Success* :返回建立成功的标志`
=============== =================================================================
**json文件需要参数**
#在yoz平面上创建Arch圆曲线,通过放样,从而生成Arch
'step' : (float)#步进,
*"SavePath" (str) 保存路径名 ,默认"Arch.3dm"*
"""
# 提取参数
dict_para = None
try:
with open(str_path, 'r') as load_file:
dict_para = json.load(load_file)
except:
print("no nonfigure file Or file is not completed")
# 参数初始化
arch_a = 5
arch_b = -2.5
step = 0.1
d = 9.936
points_phi = creat_phi_points(-180, 180, 1)
# 创建Arch.yoz面上圆形曲线的控制点
points_x = creat_crt_point(arch_a, arch_b, step, d)[1] # 得到x轴的实际坐标值点列表
parameters = creat_crt_point(arch_a, arch_b, step, d)[2] # 得到x轴的归一化坐标[0~1]
points_yz = points3d_yz = points_phi[:]
Curve = parameters[:]
points = []
# 生成若干Arch圆曲线列表
for i in range(len(points_x)):
for j in range(len(points_phi)):
points_yz[j] = CubicArchFunction(points_x[i], points_phi[j], d=9.936) # 方程得到对应x和phi(x,y,z)点值
points3d_yz[j] = listtopointed(points_yz[j])
points.append(points3d_yz)
# 再转化为每个x(i)对应的曲线
if i != 0 and i!= len(points_x)-1:
for k in range(len(points_phi)):
if k == len(points_phi)-1:
Curve[i] = Rhino.Geometry.Line(points[i][k], points[i][0])
elif 0 <= k <= len(points_phi)-1:
Curve[i] = Rhino.Geometry.Line(points[i][k], points[i][k+1])
elif i == 0 or i == len(points_x)-1:
Curve[i] = points[i][0]
# 放样 loft
lines = Curve[:]
for i in range(1,len(Curve)-1):
lines[i] = Curve[i].ToNurbsCurve()
if lines:
Arch = rs.AddLoftSrf(lines.items, start=None, end=None, loft_type=0, simplify_method=0, value=0, closed=False)
print Arch
if __name__ == "__main__":
scriptcontext.doc.Objects.Clear()
AddArch(str_parameters_file)