| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689 |
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.EditorInput;
- using Autodesk.AutoCAD.Geometry;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace CADTools
- {
-
- // 存储交点和对应等高线的数据结构
- class IntersectionResult
- {
- public List<Point3d> IntersectionPoint { get; set; }
- public Polyline Contour { get; set; }
-
- }
- class ChPLContradiction1
- {
- public static int blc;//比例尺
- public static string sqx;//首曲线
- public static string jqx;//计曲线
- public static double dgj;//计曲线
- public static string elevationLayer;//高程点图层名
- public static int num = 0;//点线矛盾点数量
- int looptimes = 5;//循环查找次数
-
-
- public void Check()
- {
- Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
- Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
- num = 0;
-
- var ptlist = GetPt(ed, db);
- for (int i = 0; i < ptlist.Count; i++)
- {
- BlockReference bf = ptlist[i];
- //为方便搜索操作,将待检查高程点设置为当前视图的中心点,视图高设置为600
- SetWindow(ed, db, bf.Position.X, bf.Position.Y, 600, 600);
- bool contradition = true;
- for (int j = 0; j < looptimes; j++)
- {
- double searchlength = 100.0 * (j + 1);
- var searchpl_horizontal = SearchDGX(bf.Position, searchlength, ed, db, 0);
- var searchpl_vertical = SearchDGX(bf.Position, searchlength, ed, db, 1);
- List<Polyline> all_pl = new List<Polyline>();
- all_pl.AddRange(searchpl_horizontal);
- foreach (var item in searchpl_vertical)
- {
- if (all_pl.Contains(item))
- continue;
- else
- all_pl.Add(item);
- }
- if (all_pl.Count < 2)
- continue;
- contradition = IfContradition(all_pl, bf.Position, searchlength);
- if (!contradition)
- break;
- }
- if (contradition)
- {
- num++;
- MakeFlag(bf.Position, blc);
-
- Point3d p1 = new Point3d(bf.Position.X - 4 * blc / 2000, bf.Position.Y - 4 * blc / 2000, 0);
- Point3d p2 = new Point3d(bf.Position.X + 4 * blc / 2000, bf.Position.Y + 4 * blc / 2000, 0);
- TypedValue[] typedvalue = new TypedValue[2];
-
- typedvalue.SetValue(new TypedValue((int)DxfCode.Start, "Text"), 0);
- typedvalue.SetValue(new TypedValue((int)DxfCode.LayerName, elevationLayer), 1);
-
- SelectionFilter filter = new SelectionFilter(typedvalue);
- PromptSelectionResult psr = ed.SelectCrossingWindow(p1, p2, filter);
- List<ObjectId> objs = new List<ObjectId>();
- if (psr.Status == PromptStatus.OK)
- {
- SelectionSet set = psr.Value;
- objs = set.GetObjectIds().ToList();
- }
- DocumentLock doclock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- if (objs.Count > 0)
- {
- for (int ii = 0; ii < objs.Count; ii++)
- {
- Entity ent = (Entity)tr.GetObject(objs[ii], OpenMode.ForWrite);
- if (ent is DBText)
- {
- DBText t = (DBText)ent;
- double T_Value = Convert.ToDouble(t.TextString);
- int ws = 0;
- if (t.TextString.Contains('.'))
- {
- ws = t.TextString.Split('.')[1].Length;
- if (t.TextString.Split('.')[1].All(c => c == '0'))
- ws = 0;
- }
- double ele = Math.Round(t.Position.Z, ws, MidpointRounding.AwayFromZero);
- if (T_Value == ele)
- {
- t.Layer = "点线矛盾高程点图层";
- t.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByLayer, 256);
- }
- }
- }
- }
-
- BlockReference blcref = (BlockReference)tr.GetObject(bf.ObjectId, OpenMode.ForWrite);
- blcref.Layer = "点线矛盾高程点图层";
- tr.Commit();
- }
- doclock.Dispose();
- }
- }
- }
-
- //获取所有高程点
- private List<BlockReference> GetPt(Editor ed,Database db)
- {
- List<BlockReference> result = new List<BlockReference>();
-
- TypedValue[] typedvalue = new TypedValue[1];
- typedvalue.SetValue(new TypedValue((int)DxfCode.LayerName, elevationLayer), 0);
- SelectionFilter selectionfilter = new SelectionFilter(typedvalue);
- PromptSelectionResult psr = ed.SelectAll(selectionfilter);
- if (psr.Status == PromptStatus.OK)
- {
- SelectionSet selectionset = psr.Value;
- ObjectId[] obj = new ObjectId[selectionset.Count];
- obj = selectionset.GetObjectIds();
- for (int i = 0; i < obj.Length; i++)
- {
- DocumentLock doclock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- ObjectId objid = obj[i];
-
- //找到实体,取高程点的位置
- Entity entity = (Entity)tr.GetObject(objid, OpenMode.ForWrite);
-
- if (entity is BlockReference)
- {
- BlockReference bf = (BlockReference)entity;
- result.Add(bf);
- }
- tr.Commit();
- }
- doclock.Dispose();
- }
- }
- return result;
- }
-
- //设置当前视图
- private void SetWindow(Editor ed, Database db,double x,double y,double width,double height)
- {
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- ViewTableRecord currview = ed.GetCurrentView();
- currview.CenterPoint = new Point2d(x, y);
- currview.ViewDirection = new Vector3d(0, 0, 1);
- currview.Width = width;
- currview.Height = height;
- ed.SetCurrentView(currview);
- tr.Commit();
- }
- }
-
- //按垂直或水平方向搜索高程点周围等高线
- private List<Polyline> SearchDGX(Point3d pt,double length,Editor ed, Database db, int direction)
- {
- List<Polyline> result = new List<Polyline>();
- Point3d startpt;
- Point3d endpt;
- if (direction == 0)
- {
- startpt = new Point3d(pt.X - length / 2, pt.Y, pt.Z);
- endpt = new Point3d(pt.X + length / 2, pt.Y, pt.Z);
- }
- else
- {
- startpt = new Point3d(pt.X, pt.Y - length / 2, pt.Z);
- endpt = new Point3d(pt.X, pt.Y + length / 2, pt.Z);
- }
- Point3dCollection ptcoll = new Point3dCollection();
- ptcoll.Add(startpt);
- ptcoll.Add(endpt);
-
- TypedValue[] typedvalue = new TypedValue[1];
- typedvalue.SetValue(new TypedValue((int)DxfCode.LayerName, sqx + "," + jqx), 0);
- SelectionFilter selectionfilter = new SelectionFilter(typedvalue);
- PromptSelectionResult psr = ed.SelectFence(ptcoll, selectionfilter);
- if (psr.Status == PromptStatus.OK)
- {
- SelectionSet selectionset = psr.Value;
- ObjectId[] obj = new ObjectId[selectionset.Count];
- obj = selectionset.GetObjectIds();
- for (int i = 0; i < obj.Length; i++)
- {
- ObjectId objid = obj[i];
- DocumentLock doclock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- Entity ent = (Entity)tr.GetObject(objid, OpenMode.ForRead);
- if(ent is Polyline)
- {
- Polyline pl = (Polyline)ent;
- result.Add(pl);
- tr.Commit();
- }
- }
- doclock.Dispose();
- }
- }
- return result;
- }
-
- //检查是否有点线矛盾
- private bool IfContradition(List<Polyline> pllist, Point3d pt, double length)
- {
- var result = new List<List<IntersectionResult>>();
-
- // 计算平移向量(以pt为基准,移动至原点)
- Vector3d translation = -pt.GetAsVector();
- Matrix3d translateMatrix = Matrix3d.Displacement(translation);
- var pt_moved = pt.TransformBy(translateMatrix);
-
- Line searchline1 = new Line(new Point3d(pt_moved.X - length / 2, pt_moved.Y, pt_moved.Z), new Point3d(pt_moved.X + length / 2, pt_moved.Y, pt_moved.Z));
- Line searchline2 = new Line(new Point3d(pt_moved.X, pt_moved.Y - length / 2, pt_moved.Z), new Point3d(pt_moved.X, pt_moved.Y + length / 2, pt_moved.Z));
-
-
- var horizontal = new List<IntersectionResult>();
- var vertical = new List<IntersectionResult>();
-
- foreach (var item in pllist)
- {
- //创建临时副本用于移动等高线,以便进行无误差的相交判断
- Polyline temppl = (Polyline)item.Clone();
-
- //应用平移变换
- temppl.TransformBy(translateMatrix);
-
- Point3dCollection horizontal_pt = new Point3dCollection();
- Point3dCollection vertical_pt = new Point3dCollection();
- var plane = new Plane(Point3d.Origin, Vector3d.ZAxis);
- temppl.IntersectWith(searchline1, Intersect.OnBothOperands, plane, horizontal_pt, IntPtr.Zero, IntPtr.Zero);
- temppl.IntersectWith(searchline2, Intersect.OnBothOperands, plane, vertical_pt, IntPtr.Zero, IntPtr.Zero);
-
- Matrix3d inverseMatrix = Matrix3d.Displacement(-translation);
- var horizontal_pt_transformed = new List<Point3d>();
- var vertical_pt_transformed = new List<Point3d>();
- if (horizontal_pt.Count != 0)
- {
- foreach (Point3d ptitem in horizontal_pt)
- horizontal_pt_transformed.Add(ptitem.TransformBy(inverseMatrix));
- horizontal.Add(new IntersectionResult { IntersectionPoint = horizontal_pt_transformed, Contour = item });
- }
- if (vertical_pt.Count != 0)
- {
- foreach (Point3d ptitem in vertical_pt)
- vertical_pt_transformed.Add(ptitem.TransformBy(inverseMatrix));
- vertical.Add(new IntersectionResult { IntersectionPoint = vertical_pt_transformed, Contour = item });
- }
- }
- //根据高程点值判断高程点两边应有的等高线高程值
- var ele1 = Math.Floor(pt.Z / dgj) * dgj;
- var ele2 = ele1 + dgj;
- if (ele1 == pt.Z)
- return true;
- Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
- //搜索是否有相应高程的等高线
- bool hastarget_horizontal = horizontal.Any(item => Math.Round(item.Contour.Elevation - ele1, db.Luprec) == 0) &&
- horizontal.Any(item => Math.Round(item.Contour.Elevation - ele2, db.Luprec) == 0);
- bool hastarget_vertical = vertical.Any(item => Math.Round(item.Contour.Elevation - ele1, db.Luprec) == 0) &&
- vertical.Any(item => Math.Round(item.Contour.Elevation - ele2, db.Luprec) == 0);
-
- //如果有,则判断高程点是否在两线之间,
- //没有的话再判断高程点是否是根据等高线变化趋势变化
- //if (hastarget_horizontal)
- //{
- // var pl1 = horizontal.FindAll(item => Math.Round(item.Contour.Elevation - ele1, db.Luprec) == 0).ToList();
- // var pl2 = horizontal.FindAll(item => Math.Round(item.Contour.Elevation - ele2, db.Luprec) == 0).ToList();
- // for (int i = 0; i < pl1.Count; i++)
- // {
- // Vector3d vec1;
- // foreach (Point3d item1 in pl1[i].IntersectionPoint)
- // {
- // vec1 = (pt - item1).GetNormal();
- // for (int ii = 0; ii < pl2.Count; ii++)
- // {
- // foreach (Point3d item2 in pl2[ii].IntersectionPoint)
- // {
- // var dot = (pt - item2).GetNormal().DotProduct(vec1);
- // if (dot <= 0)
- // return false;
- // }
- // }
- // }
- // }
- //}
- //if (hastarget_vertical)
- //{
- // var pl1 = vertical.FindAll(item => Math.Round(item.Contour.Elevation - ele1, db.Luprec) == 0).ToList();
- // var pl2 = vertical.FindAll(item => Math.Round(item.Contour.Elevation - ele2, db.Luprec) == 0).ToList();
- // for (int i = 0; i < pl1.Count; i++)
- // {
- // Vector3d vec1;
- // foreach (Point3d item1 in pl1[i].IntersectionPoint)
- // {
- // vec1 = (pt - item1).GetNormal();
- // for (int ii = 0; ii < pl2.Count; ii++)
- // {
- // foreach (Point3d item2 in pl2[ii].IntersectionPoint)
- // {
- // var dot = (pt - item2).GetNormal().DotProduct(vec1);
- // if (dot <= 0)
- // return false;
- // }
- // }
- // }
- // }
- //}
- //else
- //{
- return CheckPl(horizontal, vertical, pt);
- //只有对应方向上的多段线数量足以判断方向才进行下一步
- //if (horizontal.Count >= 2)
- //{
- // //将高程点左右的线分开,分别放到两个list
- // var side1 = new List<Point3d>();
- // var side2 = new List<Point3d>();
- // foreach (var item in horizontal)
- // {
- // foreach (var p in item.IntersectionPoint)
- // {
- // if (Math.Sign(pt.X - p.X) > 0 & !side1.Contains(p) && !side2.Contains(p))
- // side1.Add(p);
- // else if (Math.Sign(pt.X - p.X) < 0 & !side1.Contains(p) && !side2.Contains(p))
- // side2.Add(p);
- // else
- // continue;
- // }
- // }
- // //如果左右各有一条等高线,由于左右的等高线高程不是需要的高程所以为异常点
- // if (side1.Count == 1 && side2.Count == 1)
- // return true;
- // var largerList = side1.Count >= side2.Count ? side1 : side2;
- // var pts_sorted = largerList.OrderBy(p => p.DistanceTo(pt));
- // Point3d point = new Point3d();
- // Polyline pl = new Polyline();
- // foreach (var item in pts_sorted)
- // {
- // //if (point == new Point3d())
- // //{
- // // point = item;
- // // pl = horizontal.Find(p => p.IntersectionPoint.Contains(item)).Contour;
- // // if (Math.Abs(pt.Z - pl.Elevation) > dgj)
- // // return true;
- // //}
- // //else
- // //{
- // point = item;
- // //如果下一个点所在多段线不是这个点所在的多段线且高程不同,判断高程点变化方向是否一致
- // if (horizontal.Find(p => p.IntersectionPoint.Contains(item)).Contour != pl &&
- // horizontal.Find(p => p.IntersectionPoint.Contains(item)).Contour.Elevation != pl.Elevation)
- // {
- // var direction = point.Z - item.Z;
- // if (pt.Z - point.Z < 0 && direction < 0 ||
- // pt.Z - point.Z > 0 && direction > 0)
- // return false;
- // }
- // //else
- // //point = item;
- // //}
- // }
- //}
- //if (vertical.Count >= 2)
- //{
- // List<Point3d> pts = new List<Point3d>();
- // var side1 = new List<Point3d>();
- // var side2 = new List<Point3d>();
- // foreach (var item in vertical)
- // {
- // foreach (var p in item.IntersectionPoint)
- // {
- // if (Math.Sign(pt.Y - p.Y) > 0 & !side1.Contains(p) && !side2.Contains(p))
- // side1.Add(p);
- // else if (Math.Sign(pt.Y - p.Y) < 0 & !side1.Contains(p) && !side2.Contains(p))
- // side2.Add(p);
- // else
- // continue;
- // }
- // }
- // if (side1.Count == 1 && side2.Count == 1)
- // return true;
- // var largerList = side1.Count >= side2.Count ? side1 : side2;
- // var pts_sorted = largerList.OrderBy(p => p.DistanceTo(pt));
- // Point3d point = new Point3d();
- // Polyline pl = new Polyline();
- // foreach (var item in pts_sorted)
- // {
- // //if (point == new Point3d())
- // //{
- // // point = item;
- // // pl = vertical.Find(p => p.IntersectionPoint.Contains(item)).Contour;
- // // if (Math.Abs(pt.Z - pl.Elevation) > dgj)
- // // return true;
- // //}
- // //else
- // //{
- // point = item;
- // if (vertical.Find(p => p.IntersectionPoint.Contains(item)).Contour != pl)
- // {
- // var direction = point.Z - item.Z;
- // if (pt.Z - point.Z < 0 && direction < 0 ||
- // pt.Z - point.Z > 0 && direction > 0)
- // return false;
- // }
- // //else
- // //point = item;
- // //}
- // }
- //}
- //}
- //return true;
- }
-
- //标记错误点
- private void MakeFlag(Point3d pt,int blc)
- {
- double flagradius = 4.0 * blc / 1000;//根据比例尺画圆标记半径
-
- LayerControl layerscontrol = new LayerControl();
- string layname = "点线矛盾标记图层";
- if (layerscontrol.haslayername(layname) == false)
- {
- colorgb col = new colorgb(255, 0, 0);
- layerscontrol.creatlayer(layname, col);
- }
- layname = "点线矛盾高程点图层";
- if (layerscontrol.haslayername(layname) == false)
- {
- colorgb col = new colorgb(255, 255, 0);
- layerscontrol.creatlayer(layname, col);
- layerscontrol.movelayertofront(layname);
- }
-
- Database db = HostApplicationServices.WorkingDatabase;
- DocumentLock doclock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
- using (Transaction traction = db.TransactionManager.StartTransaction())
- {
- BlockTable blocktable= traction.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
- BlockTableRecord blocktablerecord = traction.GetObject(blocktable[BlockTableRecord.ModelSpace],
- OpenMode.ForWrite) as BlockTableRecord;
- Circle circ = new Circle();
- circ.Layer = "点线矛盾标记图层";
-
- circ.Center = pt;
- circ.Radius = flagradius;
- circ.Normal = new Vector3d(0, 0, 1);
- circ.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(circ);
- traction.AddNewlyCreatedDBObject(circ, true);
- traction.Commit();
-
- traction.Dispose();
- }
- doclock.Dispose();
- }
-
- private bool CheckPl(List<IntersectionResult> horizontal, List<IntersectionResult> vertical, Point3d pt)
- {
- bool constradition = true;
- bool isclosed = false;
- bool isridge = false;
- if (horizontal.Count >= 2)
- {
- //将高程点左右的线分开,分别放到两个list
- var side1 = new List<Point3d>();
- var side2 = new List<Point3d>();
- foreach (var item in horizontal)
- {
- int side1count = 0;
- int side2count = 0;
- foreach (var p in item.IntersectionPoint)
- {
- if (Math.Sign(pt.X - p.X) > 0 & !side1.Contains(p) && !side2.Contains(p)&& side1count==0)
- {
- side1.Add(p);
- side1count = 1;
- }
- else if (Math.Sign(pt.X - p.X) < 0 & !side1.Contains(p) && !side2.Contains(p)&& side2count==0)
- {
- side2.Add(p);
- side2count = 1;
- }
- else
- continue;
- }
- }
- var pl1 = new Polyline();
- var pl2 = new Polyline();
- if (side1.Count != 0 && side2.Count != 0)
- {
- var pts_sorted1 = side1.OrderBy(p => p.DistanceTo(pt)).ToList();
- var pts_sorted2 = side2.OrderBy(p => p.DistanceTo(pt)).ToList();
- pl1 = horizontal.Find(p => p.IntersectionPoint.Contains(pts_sorted1[0])).Contour;
- pl2 = horizontal.Find(p => p.IntersectionPoint.Contains(pts_sorted2[0])).Contour;
- if (pl1 != pl2)
- {
- if (pl1.Elevation < pt.Z && pt.Z < pl2.Elevation ||
- pl2.Elevation < pt.Z && pt.Z < pl1.Elevation)
- constradition = false;
- else if (pl1.Elevation == pl2.Elevation)
- {
- isridge = true;
- foreach (var item1 in pts_sorted1)
- {
- var pl3 = horizontal.Find(p => p.IntersectionPoint.Contains(item1)).Contour;
- if (pl3 != pl1)
- {
- if (pl3.Elevation < pl1.Elevation && pl1.Elevation < pt.Z ||
- pl3.Elevation > pl1.Elevation && pl1.Elevation > pt.Z)
- {
- foreach (var item2 in pts_sorted2)
- {
- var pl4 = horizontal.Find(p => p.IntersectionPoint.Contains(item2)).Contour;
- if (pl4 != pl2)
- {
- if (pl4.Elevation < pl2.Elevation && pl2.Elevation < pt.Z ||
- pl4.Elevation > pl2.Elevation && pl2.Elevation > pt.Z)
- {
- constradition = false;
- break;
- }
- }
- }
- break;
- }
- }
- }
-
- }
- else
- constradition = true;
- }
- else
- isclosed = true;
- }
- if (side1.Count != 0 && side2.Count == 0 || isclosed && side1.Count >= 2)
- {
- var pts_sorted1 = side1.OrderBy(p => p.DistanceTo(pt)).ToList();
- pl1 = horizontal.Find(p => p.IntersectionPoint.Contains(pts_sorted1[0])).Contour;
- foreach (var item in pts_sorted1)
- {
- pl2 = horizontal.Find(p => p.IntersectionPoint.Contains(item)).Contour;
- if (pl2 != pl1)
- break;
- }
- }
- else if (side1.Count == 0 && side2.Count != 0 || isclosed && side2.Count >= 2)
- {
- var pts_sorted2 = side2.OrderBy(p => p.DistanceTo(pt)).ToList();
- pl1 = horizontal.Find(p => p.IntersectionPoint.Contains(pts_sorted2[0])).Contour;
- foreach (var item in pts_sorted2)
- {
- pl2 = horizontal.Find(p => p.IntersectionPoint.Contains(item)).Contour;
- if (pl2 != pl1)
- break;
- }
- }
- if (pl1 != pl2 && side1.Count == 0|| pl1 != pl2 && side2.Count == 0|| pl1 != pl2 && isclosed)
- {
- if (pl2.Elevation < pl1.Elevation && pl1.Elevation < pt.Z ||
- pl2.Elevation > pl1.Elevation && pl1.Elevation > pt.Z)
- constradition = false;
- else
- constradition = true;
- }
- }
- if (vertical.Count >= 2 && constradition == true||isridge==true&& vertical.Count >= 2)
- {
- isclosed = false;
- //将高程点左右的线分开,分别放到两个list
- var side1 = new List<Point3d>();
- var side2 = new List<Point3d>();
- foreach (var item in vertical)
- {
- foreach (var p in item.IntersectionPoint)
- {
- if (Math.Sign(pt.Y - p.Y) > 0 & !side1.Contains(p) && !side2.Contains(p))
- side1.Add(p);
- else if (Math.Sign(pt.Y - p.Y) < 0 & !side1.Contains(p) && !side2.Contains(p))
- side2.Add(p);
- else
- continue;
- }
- }
- var pl1 = new Polyline();
- var pl2 = new Polyline();
- if (side1.Count != 0 && side2.Count != 0)
- {
- var pts_sorted1 = side1.OrderBy(p => p.DistanceTo(pt)).ToList();
- var pts_sorted2 = side2.OrderBy(p => p.DistanceTo(pt)).ToList();
- pl1 = vertical.Find(p => p.IntersectionPoint.Contains(pts_sorted1[0])).Contour;
- pl2 = vertical.Find(p => p.IntersectionPoint.Contains(pts_sorted2[0])).Contour;
- if (pl1 != pl2)
- {
- if (pl1.Elevation < pt.Z && pt.Z < pl2.Elevation ||
- pl2.Elevation < pt.Z && pt.Z < pl1.Elevation)
- constradition = false;
- else
- constradition = true;
- }
- else if (pl1.Elevation == pl2.Elevation)
- {
- isridge = true;
- foreach (var item1 in pts_sorted1)
- {
- var pl3 = vertical.Find(p => p.IntersectionPoint.Contains(item1)).Contour;
- if (pl3 != pl1)
- {
- if (pl3.Elevation < pl1.Elevation && pl1.Elevation < pt.Z ||
- pl3.Elevation > pl1.Elevation && pl1.Elevation > pt.Z)
- {
- foreach (var item2 in pts_sorted2)
- {
- var pl4 = vertical.Find(p => p.IntersectionPoint.Contains(item2)).Contour;
- if (pl4 != pl2)
- {
- if (pl4.Elevation < pl2.Elevation && pl2.Elevation < pt.Z ||
- pl4.Elevation > pl2.Elevation && pl2.Elevation > pt.Z)
- {
- constradition = false;
- break;
- }
- }
- }
- break;
- }
- }
- }
-
- }
- else
- isclosed = true;
- }
- if (side1.Count != 0 && side2.Count == 0 || isclosed && side1.Count >= 2)
- {
- var pts_sorted1 = side1.OrderBy(p => p.DistanceTo(pt)).ToList();
- pl1 = vertical.Find(p => p.IntersectionPoint.Contains(pts_sorted1[0])).Contour;
- foreach (var item in pts_sorted1)
- {
- pl2 = vertical.Find(p => p.IntersectionPoint.Contains(item)).Contour;
- if (pl2 != pl1)
- break;
- }
- }
- else if (side1.Count == 0 && side2.Count != 0 || isclosed && side2.Count >= 2)
- {
- var pts_sorted2 = side2.OrderBy(p => p.DistanceTo(pt)).ToList();
- pl1 = vertical.Find(p => p.IntersectionPoint.Contains(pts_sorted2[0])).Contour;
- foreach (var item in pts_sorted2)
- {
- pl2 = vertical.Find(p => p.IntersectionPoint.Contains(item)).Contour;
- if (pl2 != pl1)
- break;
- }
- }
- if (pl1 != pl2 && side1.Count == 0 || pl1 != pl2 && side2.Count == 0 || pl1 != pl2 && isclosed)
- {
- if (pl2.Elevation < pl1.Elevation && pl1.Elevation < pt.Z ||
- pl2.Elevation > pl1.Elevation && pl1.Elevation > pt.Z)
- constradition = false;
- else
- constradition = true;
- }
- }
- return constradition;
- }
- }
- }
|