|  | 
 
| 转自: http://cadesign.cn/bbs/thread-81-1-1.html 
 首先看下图解的过程:
 
 
 
 
 
 GH程序:
 
 ■ 折面的建立方法是使用Rectangular组件建立网格并成面获取每个面的法向及反向向量,沿两个向量移动上下两点,使用Sort Points组件重新组织点的数据顺序,用Delaunay Mesh建立折面;对于折面的连续展平使用Grasshopper目前自身的组件构建程序有些困难,可以使用Python语言来完成。对于没有Python语言编程能力的设计师,如果遇到类似的情况,可以直接调用已经编写好的“Python编写的连续展平程序”达到展平的目的;
 
 Python程序:
 import rhinoscriptsyntax as rs
 mesh=mesh  #导入外部程序的Mesh面;
 
 meshes=rs.ExplodeMeshes(mesh) #分解单一Mesh面为多个;
 
 xymeshes=[]
 for i in range(len(meshes)):
 if i ==0: #处理分解后第一个Mesh面的展平位置;
 mesh0point=rs.MeshVertices(meshes)
 mesh0points=[]
 for r in mesh0point:
 mesh0points.append([r[0],r[1],r[2]])
 
 xymesh0=rs.OrientObject(meshes,mesh0points,\
 [[0,10,0],[10,0,0],[0,0,0]],1)
 xymeshes.append(xymesh0)
 
 else: #余下Mesh面的循环遍历;
 vertices2=rs.MeshVertices(meshes)
 vertices1=rs.MeshVertices(meshes[i-1])
 
 vertices2lst=[]
 vertices1lst=[]
 for q in vertices2:
 vertices2lst.append([q[0],q[1],q[2]])
 for p in vertices1:
 vertices1lst.append([p[0],p[1],p[2]])
 
 #找到相邻两个面的共同顶点;
 ver=[m for m in vertices1lst for n in vertices2lst if m==n]
 a=ver[0]
 b=ver[1]
 #找到相邻两个面共同顶点的索引;
 indexa=vertices1lst.index(a)
 indexb=vertices1lst.index(b)
 #找到相邻两个面不共边的顶点;
 cref=[m for m in vertices1lst if m not in ver][0]
 cv=[m for m in vertices2lst if m not in ver][0]
 #定义面的延展方向;
 refvertice=rs.MeshVertices(xymeshes[i-1])
 refvertices=[]
 for x in refvertice:
 refvertices.append([x[0],x[1],x[2]])
 indexc=[c for c in range(0,3) if c !=indexa and c!=indexb]
 print(indexc)
 refverticespoint=rs.MirrorObject(rs.AddPoint(refvertices[indexc[0]]),refvertices[indexa],refvertices[indexb])
 mirrorpoint=[rs.PointCoordinates(refverticespoint)]
 
 for z in mirrorpoint:
 mirrorpoint=[z[0],z[1],z[2]]
 
 #获得面的延展;
 xymesh=rs.OrientObject(meshes,[a,b,cv],[refvertices[indexa],refvertices[indexb],mirrorpoint],1)
 xymeshes.append(xymesh)
 print(xymesh)
 
 vertices2lst=[]
 vertices1lst=[]
 ver=[]
 print(xymeshes) #可以用Print函数检查结果;
 
 ■ Python连续展平程序编写的关键是找到三维空间中与平面位置中对应点的位置,使用If条件语句来判断每一个三角面的顶点是否为同一个点,如果不共点,该点则为两个相邻三角面相互对位上的点;
 
 --Richie
 
 
 
 | 
 |