| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617 |
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.EditorInput;
- using Autodesk.AutoCAD.Geometry;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace CADTools
- {
- class Dgxthrorvrd
- {
- public static List<string> dgxlist;
- public static List<string> rvrdlist;
- public static List<string> houselist;
- public static int blc;
-
-
- public void DgxCut()
- {
- string dgxname = "";
- Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
- Database db = Autodesk.AutoCAD.DatabaseServices.HostApplicationServices.WorkingDatabase;
-
- for (int i = 0; i < dgxlist.Count; i++)
- {
- if (i == 0)
- dgxname = dgxlist[i];
- else
- dgxname = dgxname + "," + dgxlist[i];
- }
- TypedValue[] value = new TypedValue[]
- {
- new TypedValue((int)DxfCode.LayerName,dgxname)
- };
- SelectionFilter filter = new SelectionFilter(value);
- //dynamic acadApp = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
- //acadApp.ZoomExtents();
- PromptSelectionResult psr = ed.SelectAll(filter);
- if (psr.Status == PromptStatus.OK)
- {
- SelectionSet ss = psr.Value;
- ObjectIdCollection idcoll = new ObjectIdCollection(ss.GetObjectIds());
- for (int ii = 0; ii < idcoll.Count; ii++)
- {
- Polyline pll = new Polyline();
- DocumentLock doclock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
- using (Transaction trans = db.TransactionManager.StartTransaction())
- {
- Entity ent = trans.GetObject(idcoll[ii], OpenMode.ForWrite) as Entity;
- if (ent is Polyline)
- pll = (Polyline)ent;
- trans.Commit();
- }
- doclock.Dispose();
- if (pll.Database != null)
- Intersectcheck(pll, ed);
- }
- }
- dgxlist.Clear();
- if (rvrdlist != null)
- rvrdlist.Clear();
- if (houselist != null)
- houselist.Clear();
- }
-
- private void Intersectcheck(Polyline pll, Editor ed)
- {
- var plane = new Plane(Point3d.Origin, Vector3d.ZAxis);
- List<Point3d> pts = new List<Point3d>();
- List<Point3d> pts1 = new List<Point3d>();
- Point3dCollection kz_pts = new Point3dCollection();
- string rvrdname = "";
- string kzname = "";
- //为坎子让出的长度
- double cut_dist = 0.5;
- if (blc == 1000)
- cut_dist = cut_dist * 2;
- if (blc == 2000)
- cut_dist = cut_dist * 4;
- if (blc == 5000)
- cut_dist = cut_dist * 10;
- if (blc == 10000)
- cut_dist = cut_dist * 20;
-
- Database db = Autodesk.AutoCAD.DatabaseServices.HostApplicationServices.WorkingDatabase;
- //using (Transaction trans = db.TransactionManager.StartTransaction())
- //{
- //Entity ent = trans.GetObject(id, OpenMode.ForWrite) as Entity;
- //Polyline pll = new Polyline();
- //if (ent is Polyline)
- // pll = (Polyline)ent;
- //else
- // return;
- //添加道路河流的图层名并搜索相应图层上的实体
- if (rvrdlist != null)
- {
- //if (kzlist != null)
- //{
- // rvrdlist.AddRange(kzlist);
- //}
- //Point3dCollection ptcoll = new Point3dCollection();
- //for (int i = 0; i < pll.NumberOfVertices; i++)
- //{
- // ptcoll.Add(pll.GetPoint3dAt(i));
- //}
-
- rvrdname = string.Join(",", rvrdlist.Distinct());
-
- TypedValue[] value = new TypedValue[]
- {
- new TypedValue((int)DxfCode.LayerName,rvrdname)
- };
- SelectionFilter filter = new SelectionFilter(value);
- ZoomView(ed, pll.Bounds.Value.MinPoint, pll.Bounds.Value.MaxPoint);
- //PromptSelectionResult psr = ed.SelectFence(ptcoll, filter);
- PromptSelectionResult psr = ed.SelectCrossingWindow(pll.Bounds.Value.MinPoint, pll.Bounds.Value.MaxPoint, filter);
- if (psr.Status == PromptStatus.OK)
- {
- SelectionSet ss = psr.Value;
- ObjectIdCollection idcoll = new ObjectIdCollection(ss.GetObjectIds());
- for (int i = 0; i < idcoll.Count; i++)
- {
- Polyline pll_rvrd = new Polyline();
- DocumentLock doclock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
- using (Transaction trans = db.TransactionManager.StartTransaction())
- {
- Entity ent1 = trans.GetObject(idcoll[i], OpenMode.ForWrite) as Entity;
- if (ent1 is Polyline)
- pll_rvrd = (Polyline)ent1;
- trans.Commit();
- }
- doclock.Dispose();
- if (pll_rvrd.Database != null)
- {
- List<Point3d> intersectionPoints = GetIntersections(pll, pll_rvrd);
- //Point3dCollection intersectionPoints = new Point3dCollection();
- //pll.IntersectWith(pll_rvrd, Intersect.OnBothOperands, plane, intersectionPoints, IntPtr.Zero, IntPtr.Zero);
-
- if (intersectionPoints.Count > 0)
- {
- try
- {
- foreach (Point3d pt in intersectionPoints)
- {
- double param = pll.GetParameterAtPoint(pt);
- double dist = pll.GetDistanceAtParameter(param);
-
- // 检查是否与已有点的距离小于0.01
- if (!pts.Any(p => Math.Abs(pll.GetDistAtPoint(p) - dist) < 0.01))
- {
- pts.Add(pt);
- }
- }
- }
- catch
- {
- continue;
- }
- }
- }
- }
- }
- //SelectionFilter filter = new SelectionFilter(value);
- //PromptSelectionResult psr = ed.SelectAll(filter);
- //if (psr.Status == PromptStatus.OK)
- //{
- // //创建新图层
- // //LayerControl layerscontrol = new LayerControl();
- // //string layname = "待删除等高线";
- // //if (!layerscontrol.haslayername(layname))
- // //{
- // // colorgb col = new colorgb(255, 0, 255);
- // // layerscontrol.creatlayer(layname, col);
- // // layerscontrol.movelayertofront(layname);
- // //}
- // //else
- // // layerscontrol.movelayertofront(layname);
-
- // SelectionSet ss = psr.Value;
- // ObjectIdCollection idcoll = new ObjectIdCollection(ss.GetObjectIds());
- // for (int i = 0; i < idcoll.Count; i++)
- // {
- // Entity ent1 = trans.GetObject(idcoll[i], OpenMode.ForWrite) as Entity;
- // Polyline pll_rvrd = new Polyline();
- // if (ent is Polyline)
- // pll_rvrd = (Polyline)ent;
- // else
- // continue;
- // Point3dCollection intersectionPoints = new Point3dCollection();
- // pll.IntersectWith(pll_rvrd, Intersect.OnBothOperands, plane, intersectionPoints, IntPtr.Zero, IntPtr.Zero);
- // if (intersectionPoints.Count > 0)
- // {
- // foreach (Point3d pt in intersectionPoints)
- // {
- // pts.Add(pt);
- // }
- // }
- // }
- //}
- }
-
-
-
- //添加坎子图层名并搜索相应图层上的实体
- //if (kzlist != null)
- //{
- // for (int i = 0; i < kzlist.Count; i++)
- // {
- // if (i == 0)
- // kzname = kzlist[i];
- // else
- // kzname = kzname + "," + kzlist[i];
- // }
- // TypedValue[] value_kz = new TypedValue[]
- // {
- // new TypedValue((int)DxfCode.LayerName,kzname)
- // };
- // SelectionFilter filter_kz = new SelectionFilter(value_kz);
- // PromptSelectionResult psr_kz = ed.SelectAll(filter_kz);
- // if (psr_kz.Status == PromptStatus.OK)
- // {
- // SelectionSet ss = psr_kz.Value;
- // ObjectIdCollection idcoll = new ObjectIdCollection(ss.GetObjectIds());
- // for (int i = 0; i < idcoll.Count; i++)
- // {
- // Polyline pll_rvrd = new Polyline();
- // DocumentLock doclock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
- // using (Transaction trans = db.TransactionManager.StartTransaction())
- // {
- // pll_rvrd = trans.GetObject(idcoll[i], OpenMode.ForWrite) as Polyline;
- // trans.Commit();
- // }
- // doclock.Dispose();
- // //Point3dCollection intersectionPoints = new Point3dCollection();
- // //pll.IntersectWith(pll_rvrd, Intersect.OnBothOperands, plane, intersectionPoints, IntPtr.Zero, IntPtr.Zero);
- // List<Point3d> intersectionPoints = GetIntersections(pll, pll_rvrd);
- // if (intersectionPoints.Count > 0)
- // {
- // try
- // {
- // foreach (Point3d pt in intersectionPoints)
- // {
- // double param = pll.GetParameterAtPoint(pt);
- // double dist = pll.GetDistanceAtParameter(param);
-
- // // 检查是否与已有点的距离小于0.01
- // if (!pts1.Any(p => Math.Abs(pll.GetDistAtPoint(p) - dist) < 0.01))
- // {
- // pts1.Add(pt);
- // }
- // }
- // }
- // catch
- // {
- // continue;
- // }
- // }
- // }
- // #region
- // //if (pts.Count > 0)
- // //{
- // // //按参数值排序交点
- // // List<double> paramList = new List<double>();
- // // foreach (Point3d breakPoint in pts)
- // // {
- // // double param = pll.GetParameterAtPoint(breakPoint);
- // // paramList.Add(param);
- // // }
- // // paramList.Sort();
-
- // // //存储分割后的多段线
- // // List<Polyline> newPlls = new List<Polyline>();
-
- // // // 初始化第一条多段线
- // // Polyline currentPline = new Polyline();
- // // currentPline.SetDatabaseDefaults();
- // // currentPline.Layer = pll.Layer;
- // // currentPline.Color = pll.Color;
-
- // // // 遍历多段线的节点
- // // for (int i = 0; i < pll.NumberOfVertices; i++)
- // // {
- // // Point2d point = pll.GetPoint2dAt(i);
- // // double bulge = pll.GetBulgeAt(i);
-
- // // // 添加节点到当前多段线
- // // currentPline.AddVertexAt(currentPline.NumberOfVertices, point, bulge, 0, 0);
-
- // // // 检查是否需要分割
- // // if (paramList.Count > 0 && i == (int)paramList[0])
- // // {
- // // // 检查当前节点和下一个节点之间是否有交点
- // // while (paramList.Count > 0 && paramList[0] >= i && paramList[0] < i + 1)
- // // {
- // // // 计算交点处的精确位置
- // // double param = paramList[0];
- // // double dist = pll.GetDistanceAtParameter(param)- cut_dist;
- // // Point3d splitPoint3d = pll.GetPointAtDist(dist);
- // // Point2d splitPoint = new Point2d(splitPoint3d.X, splitPoint3d.Y);
- // // kz_pts.Add(splitPoint3d);
-
- // // // 添加当前多段线到结果列表
- // // currentPline.AddVertexAt(currentPline.NumberOfVertices, splitPoint, 0, 0, 0);
- // // BlockTable bt = (BlockTable)(trans.GetObject(db.BlockTableId, OpenMode.ForRead));
- // // BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- // // btr.AppendEntity(currentPline);
- // // trans.AddNewlyCreatedDBObject(currentPline, true);
- // // newPlls.Add(currentPline);
-
- // // // 初始化下一条多段线
- // // currentPline = new Polyline();
- // // currentPline.SetDatabaseDefaults();
- // // currentPline.Layer = pll.Layer;
- // // currentPline.Color = pll.Color;
-
- // // // 添加分割点作为下一条多段线的起点
- // // double dist1 = pll.GetDistanceAtParameter(param) + cut_dist;
- // // Point3d splitPoint3d1 = pll.GetPointAtDist(dist1);
- // // Point2d splitPoint1 = new Point2d(splitPoint3d1.X, splitPoint3d1.Y);
- // // kz_pts.Add(splitPoint3d1);
- // // currentPline.AddVertexAt(0, splitPoint1, 0, 0, 0);
-
- // // // 移除已处理的交点
- // // paramList.RemoveAt(0);
- // // }
- // // }
- // // }
-
- // // if (currentPline.NumberOfVertices > 0)
- // // {
- // // BlockTable bt = (BlockTable)(trans.GetObject(db.BlockTableId, OpenMode.ForRead));
- // // BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- // // btr.AppendEntity(currentPline);
- // // trans.AddNewlyCreatedDBObject(currentPline, true);
- // // newPlls.Add(currentPline);
- // // }
- // // pll.Erase();
-
-
- // // for (int i = 0; i < newPlls.Count; i++)
- // // {
- // // if (kz_pts.Contains(newPlls[i].StartPoint) &&
- // // kz_pts.Contains(newPlls[i].EndPoint) &&
- // // i % 2 == 1)
- // // newPlls[i].Layer = "待删除等高线";
- // // else if (newPlls.Count == 2)
- // // {
- // // if (newPlls[0].Length < newPlls[1].Length)
- // // newPlls[0].Layer = "待删除等高线";
- // // else
- // // newPlls[1].Layer = "待删除等高线";
- // // }
- // // }
- // //}
- // #endregion
- // }
- //}
-
-
-
- if (pts.Count > 0)
- {
- //创建新图层
- LayerControl layerscontrol = new LayerControl();
- string layname = "待删除等高线";
- if (!layerscontrol.haslayername(layname))
- {
- colorgb col = new colorgb(255, 0, 255);
- layerscontrol.creatlayer(layname, col);
- layerscontrol.movelayertofront(layname);
- }
- else
- layerscontrol.movelayertofront(layname);
- var ptssorted = pts.OrderBy(p => pll.GetDistAtPoint(p)).ToList();
- Point3dCollection ptcoll = new Point3dCollection();
- foreach (var item in ptssorted)
- {
- ptcoll.Add(item);
- }
- var splitlines = pll.GetSplitCurves(ptcoll);
- List<Polyline> split_pls = new List<Polyline>();
- for (int i = 0; i < splitlines.Count; i++)
- {
- split_pls.Add((Polyline)splitlines[i]);
- }
- var split_plssorted = split_pls.OrderBy(p => pll.GetDistAtPoint(p.StartPoint)).ToList();
- for (int i = 0; i < split_plssorted.Count; i++)
- {
- if (i % 2 != 0 && i != 0)
- {
- DocumentLock doclock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
- using (Transaction trans = db.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)(trans.GetObject(db.BlockTableId, OpenMode.ForRead));
- BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- btr.AppendEntity(split_plssorted[i]);
- trans.AddNewlyCreatedDBObject(split_plssorted[i], true);
- split_plssorted[i].Layer = "待删除等高线";
- trans.Commit();
- }
- doclock.Dispose();
- }
- else
- {
- DocumentLock doclock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
- using (Transaction trans = db.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)(trans.GetObject(db.BlockTableId, OpenMode.ForRead));
- BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- btr.AppendEntity(split_plssorted[i]);
- trans.AddNewlyCreatedDBObject(split_plssorted[i], true);
- split_plssorted[i].Layer = pll.Layer;
- trans.Commit();
- }
- doclock.Dispose();
- }
-
-
- //按参数值排序交点
- //List<double> paramList = new List<double>();
- //List<double> kzparam = new List<double>();
- //foreach (Point3d breakPoint in pts)
- //{
- // double param = pll.GetParameterAtPoint(breakPoint);
- // if (pts1.Contains(breakPoint))
- // kzparam.Add(param);
- // paramList.Add(param);
- //}
- //paramList.Sort();
-
- //存储分割后的多段线
- //List<Polyline> newPlls = new List<Polyline>();
-
- // 初始化第一条多段线
- //Polyline currentPline = new Polyline();
- //currentPline.SetDatabaseDefaults();
- //currentPline.Layer = pll.Layer;
- //currentPline.Color = pll.Color;
-
- // 遍历多段线的节点
- #region
- //for (int i = 0; i < pll.NumberOfVertices; i++)
- //{
- // Point2d point = pll.GetPoint2dAt(i);
- // double bulge = pll.GetBulgeAt(i);
-
- // // 添加节点到当前多段线
- // currentPline.AddVertexAt(currentPline.NumberOfVertices, point, bulge, 0, 0);
-
- // // 检查是否需要分割
- // if (paramList.Count > 0 && i == (int)paramList[0])
- // {
- // // 检查当前节点和下一个节点之间是否有交点
- // while (paramList.Count > 0 && paramList[0] >= i && paramList[0] < i + 1)
- // {
- // // 计算交点处的精确位置
- // double param = paramList[0];
- // double dist;
- // if (kzparam.Contains(param))
- // {
- // dist = pll.GetDistanceAtParameter(param) - cut_dist;
- // kz_pts.Add(pll.GetPointAtDist(dist));
- // }
- // else
- // dist = pll.GetDistanceAtParameter(param);
- // Point3d splitPoint3d = pll.GetPointAtDist(dist);
- // Point2d splitPoint = new Point2d(splitPoint3d.X, splitPoint3d.Y);
-
- // // 添加当前多段线到结果列表
- // currentPline.AddVertexAt(currentPline.NumberOfVertices, splitPoint, 0, 0, 0);
- // DocumentLock doclock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
- // using (Transaction trans = db.TransactionManager.StartTransaction())
- // {
- // BlockTable bt = (BlockTable)(trans.GetObject(db.BlockTableId, OpenMode.ForRead));
- // BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- // btr.AppendEntity(currentPline);
- // trans.AddNewlyCreatedDBObject(currentPline, true);
- // trans.Commit();
- // }
- // doclock.Dispose();
- // newPlls.Add(currentPline);
-
- // // 初始化下一条多段线
- // currentPline = new Polyline();
- // currentPline.SetDatabaseDefaults();
- // currentPline.Layer = pll.Layer;
- // currentPline.Color = pll.Color;
-
- // // 添加分割点作为下一条多段线的起点
- // if (kzparam.Contains(param))
- // {
- // double dist1 = pll.GetDistanceAtParameter(param) + cut_dist;
- // Point3d splitPoint3d1 = pll.GetPointAtDist(dist1);
- // Point2d splitPoint1 = new Point2d(splitPoint3d1.X, splitPoint3d1.Y);
- // kz_pts.Add(splitPoint3d1);
- // currentPline.AddVertexAt(0, splitPoint1, 0, 0, 0);
- // }
- // else
- // currentPline.AddVertexAt(0, splitPoint, 0, 0, 0);
-
- // // 移除已处理的交点
- // paramList.RemoveAt(0);
- // }
- // }
- //}
-
- //if (currentPline.NumberOfVertices > 0)
- //{
- // DocumentLock doclock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
- // using (Transaction trans = db.TransactionManager.StartTransaction())
- // {
- // BlockTable bt = (BlockTable)(trans.GetObject(db.BlockTableId, OpenMode.ForRead));
- // BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- // btr.AppendEntity(currentPline);
- // trans.AddNewlyCreatedDBObject(currentPline, true);
- // trans.Commit();
- // }
- // doclock.Dispose();
- // newPlls.Add(currentPline);
- //}
- //pll.Erase();
- #endregion
-
- //for (int i = 0; i < newPlls.Count; i++)
- //{
- // if (newPlls.Count == 2)
- // {
- // if (newPlls[0].Length < newPlls[1].Length)
- // newPlls[0].Layer = "待删除等高线";
- // else
- // newPlls[1].Layer = "待删除等高线";
- // }
- // else if (pts.Contains(newPlls[i].StartPoint) &&
- // pts.Contains(newPlls[i].EndPoint) &&
- // i % 2 == 1)
- // newPlls[i].Layer = "待删除等高线";
- // else if (kz_pts.Contains(newPlls[i].StartPoint) &&
- // kz_pts.Contains(newPlls[i].EndPoint) &&
- // i % 2 == 1)
- // newPlls[i].Layer = "待删除等高线";
- //}
- }
- DocumentLock doclock1 = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
- using (Transaction trans = db.TransactionManager.StartTransaction())
- {
- Polyline pl = trans.GetObject(pll.ObjectId, OpenMode.ForWrite) as Polyline;
- pl.Erase();
- trans.Commit();
- }
- doclock1.Dispose();
- // trans.Commit();
- //}
- }
- }
-
- /// <summary>
- /// 缩放视图以便搜索
- /// </summary>
- private void ZoomView(Editor edit, Point3d pt1, Point3d pt2)
- {
- var x_min = Math.Min(pt1.X, pt2.X);
- var y_min = Math.Min(pt1.Y, pt2.Y);
- using (ViewTableRecord currview1 = edit.GetCurrentView())
- {
- currview1.CenterPoint = new Point2d(Math.Abs((pt2.X - pt1.X) / 2) + x_min,
- Math.Abs((pt2.Y - pt1.Y) / 2) + y_min);
- currview1.Width = Math.Abs(pt2.X - pt1.X + 1);
- currview1.Height = Math.Abs(pt2.Y - pt1.Y + 1);
- edit.SetCurrentView(currview1);
- }
- }
-
- private List<Point3d> GetIntersections(Polyline pll1, Polyline pll2)
- {
- List<Point3d> result = new List<Point3d>();
-
- // 创建临时副本
- using (Polyline tempLine1 = (Polyline)pll1.Clone())
- using (Polyline tempLine2 = (Polyline)pll2.Clone())
- {
-
- // 计算平移向量(以线1起点为基准,移动至原点)
- Vector3d translation = -tempLine1.StartPoint.GetAsVector();
- Matrix3d translateMatrix = Matrix3d.Displacement(translation);
-
- // 应用平移变换
- tempLine1.TransformBy(translateMatrix);
- tempLine2.TransformBy(translateMatrix);
-
- Point3dCollection translatedPoints = new Point3dCollection();
- var plane = new Plane(Point3d.Origin, Vector3d.ZAxis);
- tempLine1.IntersectWith(tempLine2, Intersect.OnBothOperands,plane, translatedPoints, IntPtr.Zero, IntPtr.Zero);
-
- // 计算逆平移矩阵
- Matrix3d inverseMatrix = Matrix3d.Displacement(-translation);
- if (translatedPoints.Count > 0)
- {
- // 获取平移后的交点
- foreach (Point3d item in translatedPoints)
- {
- // 恢复交点坐标
- var pt = item.TransformBy(inverseMatrix);
- var pt1 = pll1.GetClosestPointTo(pt, false);
- result.Add(pt1);
- }
- translatedPoints.Dispose();
- }
- tempLine1.Dispose();
- tempLine2.Dispose();
- }
- return result;
- }
- }
- }
|