NCF参数化建筑论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 14281|回复: 8
打印 上一主题 下一主题

[研发成果] 使用Python编写连续展平程序连载(转)

[复制链接]
跳转到指定楼层
1m
发表于 2012-11-28 19:37:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
转自: 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


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏10 分享分享
2m
发表于 2012-11-28 20:22:58 | 只看该作者

很不错的分享!之前的那两个帖子让我印象深刻~~~另,这些教程是你原创的么?
3m
发表于 2012-11-28 22:44:55 | 只看该作者
赞啊!虽然我现在还看不懂...
4m
发表于 2012-11-28 23:14:58 | 只看该作者
嗯 这个值得 支持  谢谢分享 加油~~~
5m
发表于 2012-11-29 08:12:08 | 只看该作者
活建鬼 发表于 2012-11-28 20:22
很不错的分享!之前的那两个帖子让我印象深刻~~~另,这些教程是你原创的么?

richie貌似是北林的老师哦...
6m
发表于 2012-11-29 15:17:00 | 只看该作者
7m
发表于 2012-11-29 16:05:58 | 只看该作者
8m
发表于 2012-11-29 17:35:24 | 只看该作者
赞啊!python 看来得学了。。。
9m
 楼主| 发表于 2012-11-29 21:28:47 | 只看该作者
本帖最后由 RichieBall 于 2012-11-29 21:32 编辑

En, 好像是2009年末开始接触GH, 把NCF的所有帖子都读了,编些程序和大家分享 ;
把程序连上Python组件, 就不会是红的了, 同时mesh接入端右键选择List Access;
GH的Mesh处理得需要安装一些Add -ons:
Mesh Analysis and Utility Components:官方网址:http://www.grasshopper3d.com/profiles/blogs/mesh-analysis-and-utility

小黑屋|手机版|NCF参数化建筑论坛 ( 浙ICP备2020044100号-2 )    辽公网安备21021102000973号

GMT+8, 2024-4-29 20:19 , Processed in 0.095208 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表