当前位置: 首页 > article >正文

道路倒角 三角网 两侧偏移

  public void 多段线和直线两侧缓冲区()
  {
      List<Curve> ents1 = Z.db.SelectEntities<Curve>();

      List<Polyline> ents = Z.db.CurvesToPolyLines2(ents1);
      //Z.db.SelectEntities<Polyline>();
      double offsetDistance = 5.0;//p距离
      double offsetDistance2 = 1.0;//p距离
      List<Line> rightPolylines = new List<Line>();
      List<Line> rightPolylines2 = new List<Line>();
      Region myRegion = PolylineToRegion(ents, offsetDistance , offsetDistance2,out rightPolylines);
      Region myRegion2 = LineToRegion(rightPolylines, offsetDistance2, out rightPolylines2);
      myRegion.BooleanOperation(BooleanOperationType.BoolSubtract, myRegion2);  //面域相减
      //Z.db.AddEntityToModeSpace(resultPolylines.ToArray());
      //Z.db.AddEntityToModeSpace(resultCir.ToArray());
      //Z.db.AddEntityToModeSpace(regions.ToArray());
      Z.db.AddEntityToModeSpace(myRegion);
      //Z.db.AddEntityToModeSpace(rightPolylines.ToArray());
  }
  public Region PolylineToRegion(List<Polyline> ents, double offsetDistance, double offsetDistance2, out List<Line> rightPolylines)
  {
      List<Polyline> resultPolylines = new List<Polyline>();
      List<Line> rightPolylines2 = new List<Line>();
      List<Circle> resultCir = new List<Circle>();
      List<Region> regions = new List<Region>();
      DBObjectCollection tempColl = new DBObjectCollection();//
      DBObjectCollection allColl = new DBObjectCollection();//所有对象集合
      
      foreach (var item in ents)
      {   
          Polyline polyline = item;
          double radius = 0;  
          //Circle circle1 = new Circle(polyline.EndPoint, Vector3d.ZAxis, radius);//最后一个点画圆
          //circle1.ColorIndex = 1;
          //resultCir.Add(circle1);
          //allColl.Add(circle1);
          for (int i = 0; i < polyline.NumberOfVertices - 1; i++)
          {
              //if (i == polyline.NumberOfVertices - 2)
              //{
              //    Circle circle1 = new Circle(polyline.EndPoint, Vector3d.ZAxis, radius);//最后一个点画圆
              //    circle1.ColorIndex = 1;
              //    resultCir.Add(circle1);
              //    allColl.Add(circle1);   
              //}
              // polyline.GetOffsetCurvesGivenPlaneNormal(Vector3d.ZAxis, offsetDistance);
              // 获取当前段的起点和终点
              Point3d startPt = polyline.GetPoint3dAt(i);//.GetPointAt(i);
              Point3d endPt = polyline.GetPoint3dAt(i + 1);
              //Region region1 = new Region();//创建面域
              // 创建偏移的直线段
              Line lineSeg = new Line(startPt, endPt);
              DBObjectCollection offsetLineSegLeft = lineSeg.GetOffsetCurves(offsetDistance);// (offsetDistance, Vector3d.ZAxis, OffsetCurveExtensionType.Chamfer);
              DBObjectCollection offsetLineSegRight = lineSeg.GetOffsetCurves(offsetDistance * (-1.0));
              Line leftline = offsetLineSegLeft[0] as Line;
              Line rightline = offsetLineSegRight[0] as Line;
             
               radius = leftline.GetClosestPointTo(endPt, false).DistanceTo(endPt)- offsetDistance2; //  .GetDistAtPoint(endPt);
              //if (i >= 0 && i < polyline.NumberOfVertices - 2)//起始点不画圆圈
                  if (true)//起始点画圆圈
                  {
                  if (i==0)
                  {
                      Circle circle1 = new Circle(startPt, Vector3d.ZAxis, radius);
                      //circle1.ColorIndex = 1;
                      resultCir.Add(circle1);
                      allColl.Add(circle1); ;//创建圆
                  }
                  Circle circle = new Circle(endPt, Vector3d.ZAxis, radius);//创建圆
                  //circle.ColorIndex = 1;
                  resultCir.Add(circle);
                  allColl.Add(circle);
              }
             
               将偏移后的线段转换为多段线
              Polyline plLeft = new Polyline();
              //plLeft.ColorIndex = 1;
              plLeft.AddVertexAt(0, new Point2d(leftline.StartPoint.X, leftline.StartPoint.Y), polyline.GetBulgeAt(i), 0, 0);
              plLeft.AddVertexAt(1, new Point2d(leftline.EndPoint.X, leftline.EndPoint.Y), 0, 0, 0);
              resultPolylines.Add(plLeft);

              Polyline plRight = new Polyline();
              //plRight.ColorIndex = 1;
              plRight.AddVertexAt(0, new Point2d(rightline.StartPoint.X, rightline.StartPoint.Y), polyline.GetBulgeAt(i), 0, 0);
              plRight.AddVertexAt(1, new Point2d(rightline.EndPoint.X, rightline.EndPoint.Y), 0, 0, 0);
              resultPolylines.Add(plRight);
             // rightPolylines2.Add(plRight);//需要减去的里边线
              Polyline rect = new Polyline();
              rect.AddVertexAt(0, new Point2d(leftline.StartPoint.X, leftline.StartPoint.Y), polyline.GetBulgeAt(i), 0, 0);
              rect.AddVertexAt(1, new Point2d(leftline.EndPoint.X, leftline.EndPoint.Y), 0, 0, 0);
              rect.AddVertexAt(2, new Point2d(rightline.EndPoint.X, rightline.EndPoint.Y), polyline.GetBulgeAt(i) * (-1), 0, 0);
              rect.AddVertexAt(3, new Point2d(rightline.StartPoint.X, rightline.StartPoint.Y), 0, 0, 0);
              //rect.ColorIndex = 1;
              rect.Closed = true;
              //Z.db.AddEntityToModeSpace(rect);//画多段线
              allColl.Add(rect);
          }
       
          tempColl = Region.CreateFromCurves(allColl);//region的边界是一个对象集合
          for (int j = 0; j < tempColl.Count; j++)//这里不可以-1
          {
              regions.Add(tempColl[j] as Region);//加入retions
              //regions[j].ColorIndex = 1;
          }


      }
      Region combinedRegion = new Region();
      foreach (Region region in regions)
      {
          combinedRegion.BooleanOperation(BooleanOperationType.BoolUnite, region);
      }
      DBObjectCollection dbc = new DBObjectCollection();
      combinedRegion.Explode( dbc );
      foreach (var item in dbc)
      {
          if (item is Line line )
          {
              //Polyline pl = new Polyline();
              //pl.AddVertexAt(0, new Point2d(line.StartPoint.X, line.StartPoint.Y), 0, 0, 0);
              rightPolylines2.Add(line);
          }
          
      }
      rightPolylines = rightPolylines2;
      return combinedRegion;
  }
  public Region LineToRegion(List<Line> ents, double offsetDistance, out List<Line> rightPolylines)
  {
      List<Polyline> resultPolylines = new List<Polyline>();
      List<Line> rightPolylines2 = new List<Line>();
      List<Circle> resultCir = new List<Circle>();
      List<Region> regions = new List<Region>();
      DBObjectCollection tempColl = new DBObjectCollection();//
      DBObjectCollection allColl = new DBObjectCollection();//所有对象集合
      List<Line> linerep = Outershape.RepairLine(ents);
      foreach (var item in linerep)
      {
          Point3d startPt = item.StartPoint;
          Point3d endPt = item.EndPoint;
          DBObjectCollection offsetLineSegLeft = item.GetOffsetCurves(offsetDistance);// (offsetDistance, Vector3d.ZAxis, OffsetCurveExtensionType.Chamfer);
          DBObjectCollection offsetLineSegRight = item.GetOffsetCurves(offsetDistance * (-1.0));
          Line leftline = offsetLineSegLeft[0] as Line;
          Line rightline = offsetLineSegRight[0] as Line;
          double radius = leftline.GetClosestPointTo(endPt, false).DistanceTo(endPt); //  .GetDistAtPoint(endPt);                                                                              //{
          Circle circle = new Circle(endPt, Vector3d.ZAxis, radius);//创建圆
          //circle.ColorIndex = 1;
          resultCir.Add(circle);
          allColl.Add(circle);
      }
          foreach (var item in ents)
          {
              Point3d startPt = item.StartPoint;
              Point3d endPt = item.EndPoint;
              DBObjectCollection offsetLineSegLeft = item.GetOffsetCurves(offsetDistance);// (offsetDistance, Vector3d.ZAxis, OffsetCurveExtensionType.Chamfer);
              DBObjectCollection offsetLineSegRight = item.GetOffsetCurves(offsetDistance * (-1.0));
              Line leftline = offsetLineSegLeft[0] as Line;
              Line rightline = offsetLineSegRight[0] as Line;
              //double radius = leftline.GetClosestPointTo(endPt, false).DistanceTo(endPt); //  .GetDistAtPoint(endPt);                                                                              //{
              //Circle circle = new Circle(endPt, Vector3d.ZAxis, radius);//创建圆
              //circle.ColorIndex = 1;
              //resultCir.Add(circle);
              //allColl.Add(circle);
          //}
           将偏移后的线段转换为多段线
          Polyline plLeft = new Polyline();//画左边线
          //plLeft.ColorIndex = 1;
          plLeft.AddVertexAt(0, new Point2d(leftline.StartPoint.X, leftline.StartPoint.Y), 0, 0, 0);
          plLeft.AddVertexAt(1, new Point2d(leftline.EndPoint.X, leftline.EndPoint.Y), 0, 0, 0);
          resultPolylines.Add(plLeft);

          Polyline plRight = new Polyline();//画右边线
          //plRight.ColorIndex = 1;
          plRight.AddVertexAt(0, new Point2d(rightline.StartPoint.X, rightline.StartPoint.Y),0, 0, 0);
          plRight.AddVertexAt(1, new Point2d(rightline.EndPoint.X, rightline.EndPoint.Y), 0, 0, 0);
          resultPolylines.Add(plRight);
           rightPolylines2.Add(plRight);//需要减去的里边线
          Polyline rect = new Polyline();//画矩形
          rect.AddVertexAt(0, new Point2d(leftline.StartPoint.X, leftline.StartPoint.Y), 0, 0, 0);
          rect.AddVertexAt(1, new Point2d(leftline.EndPoint.X, leftline.EndPoint.Y), 0, 0, 0);
          rect.AddVertexAt(2, new Point2d(rightline.EndPoint.X, rightline.EndPoint.Y), 0, 0, 0);
          rect.AddVertexAt(3, new Point2d(rightline.StartPoint.X, rightline.StartPoint.Y), 0, 0, 0);
          //rect.ColorIndex = 1;
          rect.Closed = true;
          //Z.db.AddEntityToModeSpace(rect);//画多段线
          allColl.Add(rect);
          //}
          tempColl = Region.CreateFromCurves(allColl);//region的边界是一个对象集合
          for (int j = 0; j < tempColl.Count; j++)//这里不可以-1
          {
              regions.Add(tempColl[j] as Region);//加入retions
              //regions[j].ColorIndex = 1;
          }


      }
      Region combinedRegion = new Region();
      foreach (Region region in regions)
      {
          combinedRegion.BooleanOperation(BooleanOperationType.BoolUnite, region);
      }
      DBObjectCollection dbc = new DBObjectCollection();
      combinedRegion.Explode(dbc);
      foreach (var item in dbc)
      {
          if (item is Line line)
          {
              //Polyline pl = new Polyline();
              //pl.AddVertexAt(0, new Point2d(line.StartPoint.X, line.StartPoint.Y), 0, 0, 0);
              rightPolylines2.Add(line);
          }

      }
      rightPolylines = rightPolylines2;
      return combinedRegion;
  }

c5c09b75fd6e414d94ee56264e136946.jpg

 

 

 


http://www.kler.cn/a/457454.html

相关文章:

  • (二)当人工智能是一个函数,函数形式怎么选择?ChatGPT的函数又是什么?
  • 《代码随想录》Day24打卡!
  • 15. 接雨水
  • 鸿蒙HarmonyOS开发:拨打电话、短信服务、网络搜索、蜂窝数据、SIM卡管理、observer订阅管理
  • Spring Boot 中的 classpath详解
  • Vue.js组件开发-使用KeepAlive缓存特定组件
  • 2025最新植物大战僵尸杂交版3.0.2版本
  • 埃斯顿机器人程序案例多个点位使用变量
  • 微服务架构与 Spring Cloud 相关技术解读
  • 程序猿成长之路之设计模式篇——结构型设计模式
  • C 中如何在For中生成不重复的随机数
  • 【Chrome】浏览器提示警告Chrome is moving towards a new experience
  • 邮件传输协议
  • Linux系统编程(一)--基础指令
  • 【Spring】基于注解的Spring容器配置——基于Java类的配置(@Configuration与@Bean)
  • 【MySQL篇】使用Java操作MySQL实现数据交互
  • 基于python的ai五子棋游戏
  • .net core 的算法与数据结构
  • 【华为OD-E卷-取出尽量少的球 100分(python、java、c++、js、c)】
  • 【Pandas】pandas Series to_numpy
  • 路由器刷机TP-Link tp-link-WDR5660 路由器升级宽带速度
  • TCP/IP网络协议攻击
  • PyTorch快速入门教程【小土堆】之TensorBoard的使用
  • 深度学习的魔法世界
  • SpringCloud 系列教程:微服务的未来(二)Mybatis-Plus的条件构造器、自定义SQL、Service接口基本用法
  • RabbitMQ的优缺点:深入解析消息队列的核心力量