找回密码
 注册
搜索
查看: 31155|回复: 12

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

 火 [复制链接]
发表于 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

100.png
points number - > 500

500.png
points number - > 1000

123.png
points number - > 1000

cube.png
closet line with intersction check.gh (7.05 KB, 下载次数: 38, 售价: 1 lux照度)


发表于 2013-2-26 22:59:31 | 显示全部楼层
学习了~~~~~~~~~~
回复

使用道具 举报

发表于 2013-2-27 12:02:51 | 显示全部楼层
也是用dropbox..支持一个.GH小白,尤其对数据部分不清楚...
回复

使用道具 举报

发表于 2013-2-27 15:47:02 | 显示全部楼层

学习了~~~~~~~~~~
回复

使用道具 举报

发表于 2013-2-27 21:38:35 | 显示全部楼层
这个真心屌。。。。
回复

使用道具 举报

发表于 2013-2-28 22:47:49 | 显示全部楼层
崇拜~   论坛多一点这样的帖子就好了!
回复

使用道具 举报

发表于 2013-3-1 06:03:04 | 显示全部楼层
学习了~~~谢谢楼主
回复

使用道具 举报

发表于 2013-3-1 10:24:45 | 显示全部楼层
坛子子里久违的帖子了
真心感谢楼主
回复

使用道具 举报

发表于 2013-3-1 17:54:55 | 显示全部楼层
非常高端啊{:08:}
回复

使用道具 举报

发表于 2013-3-1 20:33:56 | 显示全部楼层
下来研究一下~
回复

使用道具 举报

发表于 2014-1-9 00:38:44 | 显示全部楼层
非常不错的尝试学习啦
回复

使用道具 举报

发表于 2014-9-7 23:44:04 来自手机 | 显示全部楼层
感谢LZ,目前正在学习C#,学习了
回复

使用道具 举报

发表于 2016-10-6 19:51:52 | 显示全部楼层
感谢分享………………
回复

使用道具 举报

NCFZ微信公众号

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

GMT+8, 2026-11-23 19:56 , Processed in 0.056734 second(s), 29 queries , Gzip On.

Powered by Discuz! X5.0 Licensed

© 2001-2026 Discuz! Team.

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