NCF参数化建筑论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 18699|回复: 12
打印 上一主题 下一主题

[VB & C#] <分享>使用GH C#找出最近點連線並檢查是否交集

  [复制链接]
跳转到指定楼层
1m
发表于 2013-2-26 21:28:05 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
檔案 :

https://dl.dropbox.com/u/29860061/closet%20line%20with%20intersction%20check.gh

流程步驟 :

1.散佈隨機點在範圍內,設index 0 為起始點。
使用舊點雲(intput x)計算出基準點(basePoint)與新點雲(calNewCloudPts2)。
新點雲中不包含基準點(basePoint)。
public List<Point3d> calNewCloudPts(int basePtIndex, List<Point3d> oldCloudPts){...}

2.使用基準點(basePoint)與新點雲(calNewCloudPts2)搜尋最近點,並儲存當下indexNumber (calNewCloudPts2[closePtIndex])。
public int calculateDist(List < Point3d > calPts, Point3d startPt){...}

3. 使用基準點(basePoint)與最近點(calNewCloudPts2[closePtIndex])相連線(尚未放入LIST中)。
public Line LinkLn(Point3d startPt, Point3d endPt){...}

4.檢查最新連線(myLine)是否與舊有線段(mylnList)相互交集,如果有交集->不連線,如果沒交集->產生新線段,並放入LIST當中。
public bool checkInt(List<Line> lnA, Line lnB){...}

5. 更新基準點(basePoint)與最近點(calNewCloudPts2[closePtIndex])。


initialnum = closePtIndex;
x = calNewCloudPts2;


6.重複1-5步驟,完成最近距離連線

Main Code:


private void RunScript(List<Point3d> x, Point3d y, ref object A)
  {

    List < Line > mylnList = new List < Line >();
    List<Point3d> calNewCloudPts2 = new List<Point3d>();
    Point3d basePoint = new Point3d();

    //the initial index is 0
    int initialnum = 0;
    int closePtIndex = 0;
    int totaloldPtsLength = x.Count - 1;
    Line myLine;
    bool mytest = false;




    for(int i = 0;i < totaloldPtsLength;i++){

      basePoint = x[initialnum];
      calNewCloudPts2 = calNewCloudPts(initialnum, x);
      closePtIndex = calculateDist(calNewCloudPts2, basePoint);
      //Print("closePtIndex  = {0}", closePtIndex);
      myLine = LinkLn(basePoint, calNewCloudPts2[closePtIndex]);

      mytest = checkInt(mylnList, myLine);

      Print("ff = {0}", mytest);
      if(mytest == false){
        mylnList.Add(myLine);

      }

      initialnum = closePtIndex;
      x = calNewCloudPts2;
      Print("calNewCloudPts2 List = {0}", calNewCloudPts2.Count.ToString());

    }

    //Print("x count = {0}", x.Count.ToString());


    A = mylnList;



  }

結果圖片:

points number - > 100

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏2 分享分享
2m
发表于 2013-2-26 22:59:31 | 只看该作者
学习了~~~~~~~~~~
3m
发表于 2013-2-27 12:02:51 | 只看该作者
也是用dropbox..支持一个.GH小白,尤其对数据部分不清楚...
4m
发表于 2013-2-27 15:47:02 | 只看该作者

学习了~~~~~~~~~~
5m
发表于 2013-2-27 21:38:35 | 只看该作者
这个真心屌。。。。
6m
发表于 2013-2-28 22:47:49 | 只看该作者
崇拜~   论坛多一点这样的帖子就好了!
7m
发表于 2013-3-1 06:03:04 | 只看该作者
学习了~~~谢谢楼主
8m
发表于 2013-3-1 10:24:45 | 只看该作者
坛子子里久违的帖子了
真心感谢楼主
9m
发表于 2013-3-1 17:54:55 | 只看该作者
非常高端啊{:08:}
10m
发表于 2013-3-1 20:33:56 | 只看该作者
下来研究一下~
11m
发表于 2014-1-9 00:38:44 | 只看该作者
非常不错的尝试学习啦
12m
发表于 2014-9-7 23:44:04 来自手机 | 只看该作者
感谢LZ,目前正在学习C#,学习了
13m
发表于 2016-10-6 19:51:52 | 只看该作者
感谢分享………………

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

GMT+8, 2024-4-19 23:13 , Processed in 0.098183 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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