| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923 |
- using System;
- using System.Collections.Generic;
- using Autodesk.Revit.DB;
- using SAGA.DotNetUtils;
- using SAGA.DotNetUtils.Extend;
- using SAGA.RevitAPI;
- using SAGA.RevitUtils.Infrastructure;
- namespace SAGA.RevitUtils.Extends
- {
- public static class LineExtend
- {
- /// <summary>
- /// 增加z值
- /// </summary>
- /// <param name="line"></param>
- /// <param name="dZ"></param>
- /// <returns></returns>
- public static Line AddZ(this Line line, double dZ)
- {
- XYZ ptS = line.StartPoint().AddZ(dZ);
- XYZ ptE = line.EndPoint().AddZ(dZ);
- return Line.CreateBound(ptS, ptE);
- }
- /// <summary>
- /// 修改z值
- /// </summary>
- /// <param name="line"></param>
- /// <param name="dZ"></param>
- /// <returns></returns>
- public static Line NewZ(this Line line, double dZ=0)
- {
- XYZ ptS = line.StartPoint().NewZ(dZ);
- XYZ ptE = line.EndPoint().NewZ(dZ);
- if (ptS.IsEqual(ptE))
- {
- return null;
- }
- return Line.CreateBound(ptS, ptE);
- }
- /// <summary>
- /// 绕起点旋转
- /// </summary>
- /// <param name="line"></param>
- /// <param name="angle">旋转角度(弧度)</param>
- /// <returns></returns>
- public static Line RotateByStart(this Line line, double angle)
- {
- Transform tranform = Transform.CreateRotationAtPoint(XYZ.BasisZ, angle, line.StartPoint());
- Line result = (Line)line.CreateTransformed(tranform);
- return result;
- }
-
- /// <summary>
- /// 过点pt与line垂直的射线
- /// </summary>
- /// <param name="line"></param>
- /// <param name="pt"></param>
- /// <returns></returns>
- public static Line GetVUnboundLine(this Line line, XYZ pt)
- {
- double dAngle = Math.PI / 2;
- XYZ vecDir = line.Direction.VectorRotate(dAngle);
- return Line.CreateUnbound(pt, vecDir);
- }
- /// <summary>
- /// 三维中直线与其XY平面投影线所成夹角,就是坡度
- /// </summary>
- /// <param name="line"></param>
- /// <returns></returns>
- public static double GetSlopeAngleZ(this Line line)
- {
- double dRtn = 0;
- double dH = Math.Abs(line.StartPoint().Z - line.EndPoint().Z);
- double dL = line.Length;
- dRtn = Math.Asin(dH / dL);
- return dRtn;
- }
- /// <summary>
- /// 坡度的起点,即檐口处理点
- /// </summary>
- /// <param name="line"></param>
- /// <returns></returns>
- public static XYZ GetSlopeStartPoint(this Line line)
- {
- XYZ ptRtn = null;
- double dAngle = line.GetSlopeAngleZ();
- if (dAngle.IsEqual(0))
- {
- ptRtn = line.StartPoint();
- }
- else
- {
- if (line.StartPoint().Z < line.EndPoint().Z)
- {
- ptRtn = line.StartPoint();
- }
- else
- {
- ptRtn = line.EndPoint();
- }
- }
- return ptRtn;
- }
- /// <summary>
- /// 以直线中点为基点,向两边延展n个直线单位向量做新直线
- /// </summary>
- /// <param name="line"></param>
- /// <param name="n"></param>
- /// <returns></returns>
- public static Line ExtendLengthByMiddle(this Line line, uint n)
- {
- XYZ direction = line.Direction;
- XYZ m = line.MiddlePoint();
- return Line.CreateBound(m - direction * n, m + direction * n);
- }
- /// <summary>
- /// 偏移到点
- /// </summary>
- /// <param name="line"></param>
- /// <param name="pt">过某一点</param>
- /// <returns></returns>
- public static Line OffsetPoint(this Line line, XYZ pt)
- {
- XYZ ptV = line.VerticalPoint(pt);
- XYZ vec = pt.Subtract(ptV);
- return line.OffsetVector(vec).GetLine();
- }
- /// <summary>
- /// 两直线平行
- /// </summary>
- /// <param name="line1"></param>
- /// <param name="line2"></param>
- /// <param name="tolerance"></param>
- /// <param name="hasDirection">是否区分方向</param>
- /// <returns></returns>
- public static bool IsParallel(this Line line1, Line line2, double tolerance = 0.0, bool hasDirection = false)
- {
- if (hasDirection)
- {
- return line1.Direction.IsEqual(line2.Direction, tolerance);
- }
- if (!line1.Direction.IsEqual(line2.Direction, tolerance))
- {
- return line1.Direction.IsEqual(-line2.Direction, tolerance);
- }
- return true;
- }
- /// <summary>
- /// 偏移,区分正负值
- /// </summary>
- /// <param name="line"></param>
- /// <param name="dValue">大于零、小于零</param>
- /// <returns></returns>
- public static Line Offset(this Line line, double dValue)
- {
- XYZ vec = line.Direction.Normalize().VectorRotate(Math.PI / 2) * dValue;
- return line.OffsetVector(vec).GetLine();
- }
- /// <summary>
- /// 相等
- /// </summary>
- /// <param name="line1"></param>
- /// <param name="line2"></param>
- /// <param name="useDirection">考虑方向</param>
- /// <param name="tolerance"></param>
- /// <returns></returns>
- public static bool IsEqual(this Line line1, Line line2, bool useDirection = false, double tolerance = 0)
- {
- if (useDirection)
- {
- return line1.StartPoint().IsEqual(line2.StartPoint(), tolerance) &&
- line1.EndPoint().IsEqual(line2.EndPoint(), tolerance);
- }
- else
- {
- return ((line1.StartPoint().IsEqual(line2.StartPoint(), tolerance) &&
- line1.EndPoint().IsEqual(line2.EndPoint(), tolerance)) ||
- (line1.StartPoint().IsEqual(line2.EndPoint(), tolerance) &&
- line1.EndPoint().IsEqual(line2.StartPoint(), tolerance)));
- }
- }
- /// <summary>
- /// 相等,不考虑Z坐标
- /// </summary>
- /// <param name="line1"></param>
- /// <param name="line2"></param>
- /// <param name="useDirection"></param>
- /// <param name="tolerance"></param>
- /// <returns></returns>
- public static bool IsEqual2(this Line line1, Line line2, bool useDirection = false, double tolerance = 0)
- {
- return line1.NewZ().IsEqual(line2.NewZ(), useDirection, tolerance);
- }
- /// <summary>
- /// 反向
- /// </summary>
- /// <param name="line"></param>
- /// <returns></returns>
- public static Line Reverse(this Line line)
- {
- return line.IsBound
- ? Line.CreateBound(line.EndPoint(), line.StartPoint())
- : Line.CreateUnbound(line.Origin, -line.Direction);
- }
- /// <summary>
- /// 水平线
- /// </summary>
- /// <param name="line"></param>
- /// <returns></returns>
- public static bool IsHorizontal(this Line line)
- {
- return line.StartPoint().Y.IsEqual(line.EndPoint().Y);
- }
- /// <summary>
- /// 垂直线
- /// </summary>
- /// <param name="line"></param>
- /// <returns></returns>
- public static bool IsVertical(this Line line, double tolerance = 0.0)
- {
- return line.StartPoint().X.IsEqual(line.EndPoint().X, tolerance);
- }
-
- /// <summary>
- /// 获取相对X轴倾斜角度
- /// </summary>
- /// <param name="line"></param>
- /// <returns></returns>
- public static double GetSlopeAngle(this Line line)
- {
- return line.GetSlopeRadian().ToAngle();
- }
- /// <summary>
- /// 获取相对X轴倾斜弧度
- /// </summary>
- /// <param name="line">直线</param>
- /// <returns></returns>
- public static double GetSlopeRadian(this Line line)
- {
- XYZ vec = line.UnitVector();
- return vec.QuadrantAngle();
- }
- /// <summary>
- /// 直线垂直
- /// </summary>
- /// <param name="line1"></param>
- /// <param name="line2"></param>
- /// <returns></returns>
- public static bool IsVertical(this Line line1, Line line2, double tolerance = 0.0)
- {
- return line1.Direction.IsVertical(line2.Direction, tolerance);
- }
- /// <summary>
- /// 判断线段是否在多边形内,注意Z坐标
- /// </summary>
- /// <param name="line"></param>
- /// <param name="listProfile"></param>
- /// <returns></returns>
- public static bool LineInPolygon(this Line line, List<Curve> listProfile)
- {
- //if 线端PQ的端点不都在多边形内
- // then return false;
- XYZ ptSl = line.StartPoint();
- XYZ ptEl = line.EndPoint();
- if (!ptSl.PointInPolygon2(listProfile) && !ptSl.PointInPoly(listProfile))
- return false;
- //bool blnRtn = ptSL.PointInPolygon2(listProfile);
- //if (!blnRtn)
- //{
- // return false;
- //}
- if (!ptEl.PointInPolygon2(listProfile) && !ptEl.PointInPoly(listProfile))
- return false;
- //blnRtn = ptEL.PointInPolygon2(listProfile);
- //if (!blnRtn)
- //{
- // return false;
- //}
- //点集pointSet初始化为空;
- List<XYZ> listPt = new List<XYZ>();
- //for 多边形的每条边s
- foreach (Curve curve in listProfile)
- {
- // do if 线段的某个端点在s上
- // then 将该端点加入pointSet;
- bool blnTmep1 = curve.IsOnCurve(ptSl);
- bool blnTmep2 = curve.IsOnCurve(ptEl);
- if (blnTmep1 || blnTmep2)
- {
- if (blnTmep1)
- {
- if (!ptSl.ExsitsInlist(listPt))
- {
- listPt.Add(ptSl);
- }
- }
- if (blnTmep2)
- {
- if (!ptEl.ExsitsInlist(listPt))
- {
- listPt.Add(ptEl);
- }
- }
- }
- else
- {
- // else if s的某个端点在线段PQ上
- // then 将该端点加入pointSet;
- XYZ ptSs = curve.StartPoint();
- XYZ ptEs = curve.EndPoint();
- blnTmep1 = line.IsOnCurve(ptSs);
- blnTmep2 = line.IsOnCurve(ptEs);
- if (blnTmep1 || blnTmep2)
- {
- if (blnTmep1)
- {
- if (!ptSs.ExsitsInlist(listPt))
- {
- listPt.Add(ptSs);
- }
- }
- if (blnTmep2)
- {
- if (!ptEs.ExsitsInlist(listPt))
- {
- listPt.Add(ptEs);
- }
- }
- }
- else
- {
- //else if s和线段PQ相交 // 这时候已经可以肯定是内交了
- //then return false;
- if (curve.IsIntersection(line))
- {
- return false;
- }
- }
- }
- }
- //将pointSet中的点按照X-Y坐标排序;
- listPt.Sort(new XyzComparer());
- //for pointSet中每两个相邻点 pointSet[i] , pointSet[ i+1]
- //do if pointSet[i] , pointSet[ i+1] 的中点不在多边形中
- //then return false;
- for (int i = 0; i < listPt.Count - 1; i++)
- {
- XYZ ptMid = listPt[i].MiddlePoint(listPt[i + 1]);
- if (!ptMid.PointInPolygon2(listProfile) && !ptMid.PointInPoly(listProfile))
- return false;
- //blnRtn = ptMid.PointInPolygon2(listProfile);
- //if (!blnRtn)
- //{
- // return false;
- //}
- }
- return true;
- }
- /// <summary>
- /// 线与多边型相交,注意Z坐标
- /// </summary>
- /// <param name="line"></param>
- /// <param name="listProfile"></param>
- /// <returns></returns>
- public static bool LineIntersectPolygon(this Line line, List<Curve> listProfile)
- {
- bool blnRtn = false;
- foreach (Curve curve in listProfile)
- {
- if (curve == null) return false;
- blnRtn = curve.IsIntersection(line);
- if (blnRtn)
- {
- break;
- }
- }
- return blnRtn;
- }
- /// <summary>
- /// 等分点的中点
- /// </summary>
- /// <param name="line"></param>
- /// <param name="intCount"></param>
- /// <returns></returns>
- public static List<XYZ> GetCountPoints(this Line line, int intCount)
- {
- List<XYZ> listRtn = new List<XYZ>();
- XYZ[] pts = line.GetDividePoints(intCount);
- for (int i = 0; i < pts.Length - 1; i++)
- {
- listRtn.Add(pts[i].MiddlePoint(pts[i + 1]));
- }
- return listRtn;
- }
- /// <summary>
- /// 共线下,IsUnite=true,返回合并曲线;IsUnite=false 返回相离曲线
- /// </summary>
- public static Line CombinDisjiont(this Line curve1, Line curve2, bool isUnite, double tolerance = 0)
- {
- isUnite = !isUnite;
- if (null == curve2 || !curve1.IsBound || !curve2.IsBound || !curve1.IsOnCurve(curve2)) return null;
- Curve temp = curve1.SameDirection(curve2) ? curve2 : curve2.Reverse();
- if (curve1.IsOnCurve(temp.StartPoint())) return null; //两曲线不相离返回null
- XYZ startPoint1 = curve1.StartPoint(), endPoint1 = curve1.EndPoint();
- XYZ startPoint2 = temp.StartPoint(), endPoint2 = temp.EndPoint();
- XYZ start, end;
- if (endPoint1.DistanceTo(startPoint2) > endPoint1.DistanceTo(endPoint2)) //curve2在curve1顺方向
- {
- start = isUnite ? startPoint1 : endPoint1;
- end = isUnite ? endPoint2 : startPoint2;
- }
- else //curve2在curve1逆方向
- {
- start = isUnite ? startPoint2 : endPoint2;
- end = isUnite ? endPoint1 : startPoint1;
- }
- return Line.CreateBound(start, end);
- }
- /// <summary>
- /// 合并两条线段
- /// </summary>
- /// <param name="line1"></param>
- /// <param name="line2"></param>
- /// <param name="tolerance"></param>
- /// <returns></returns>
- public static Line CombineLine(this Line line1, Line line2, double tolerance = 0.0)
- {
- return line1.CombineLineNew(line2, true, tolerance);
- }
- /// <summary>
- /// 合并两条线段,IsUnite=false时,仅返回重叠部分曲线,
- /// </summary>
- /// <param name="line1"></param>
- /// <param name="line2"></param>
- /// <param name="isUnite"></param>
- /// <param name="tolerance"></param>
- /// <returns></returns>
- public static Line CombineLine(this Line line1, Line line2, bool isUnite, double tolerance = 0.0)
- {
- if ((line1.IsBound && line2.IsBound) && line1.IsParallel(line2, 0.0, false))
- {
- Line curve = line1.Direction.IsEqual(line2.Direction, 0.0) ? line2 : line2.Reverse().GetLine();
- XYZ first = null;
- if (line1.IsContain(curve.StartPoint(), tolerance))
- {
- first = isUnite ? line1.StartPoint() : curve.StartPoint();
- }
- else if (curve.IsContain(line1.StartPoint(), tolerance))
- {
- first = isUnite ? curve.StartPoint() : line1.StartPoint();
- }
- XYZ second = null;
- if (line1.IsContain(curve.EndPoint(), tolerance))
- {
- second = isUnite ? line1.EndPoint() : curve.EndPoint();
- }
- else if (curve.IsContain(line1.EndPoint(), tolerance))
- {
- second = isUnite ? curve.EndPoint() : line1.EndPoint();
- }
- if (((first != null) && (second != null)) && !first.IsEqual(second, 0.0))
- {
- return CreateBoundExt(first, second);
- }
- }
- return null;
- }
- /// <summary>
- /// 合并两条线段(共线,不相交也可合并)
- /// </summary>
- /// <param name="line1"></param>
- /// <param name="line2"></param>
- /// <param name="tolerance"></param>
- /// <returns></returns>
- public static Line CombineLine2(this Line line1, Line line2, double tolerance = 0.0)
- {
- if ((line1.IsBound && line2.IsBound) && line1.IsParallel(line2, 0.0, false))
- {
- List<XYZ> list = new List<XYZ> {
- line1.StartPoint(),
- line1.EndPoint(),
- line2.StartPoint(),
- line2.EndPoint()
- };
- list.Sort(new XyzComparer(false));
- return CreateBoundExt(list[0], list[list.Count - 1]);
- }
- return null;
- }
- public static Line CombineLineNew(this Line line1, Line line2, bool isUnite, double tolerance = 0.0)
- {
- Predicate<Line> match = null;
- Predicate<Line> predicate2 = null;
- if ((!line1.IsBound || !line2.IsBound) || !line1.IsParallel(line2, 0.0, false))
- {
- return null;
- }
- if ((!line2.IsContain(line1.StartPoint(), tolerance) && !line2.IsContain(line1.EndPoint(), tolerance)) && (!line1.IsContain(line2.StartPoint(), tolerance) && !line1.IsContain(line2.EndPoint(), tolerance)))
- {
- return null;
- }
- if (line1.IsInLine(line2, tolerance))
- {
- return line2;
- }
- if (line2.IsInLine(line1, tolerance))
- {
- return line1;
- }
- List<Line> list = new List<Line>();
- Line item = CreateBoundExt(line1.StartPoint(), line2.StartPoint());
- if (item != null)
- {
- list.Add(item);
- }
- Line line3 = CreateBoundExt(line1.StartPoint(), line2.EndPoint());
- if (line3 != null)
- {
- list.Add(line3);
- }
- Line line4 = CreateBoundExt(line1.EndPoint(), line2.StartPoint());
- if (line4 != null)
- {
- list.Add(line4);
- }
- Line line5 = CreateBoundExt(line1.EndPoint(), line2.EndPoint());
- if (line5 != null)
- {
- list.Add(line5);
- }
- if (!isUnite)
- {
- if (match == null)
- {
- match = p => p.IsInLine(line1, tolerance) && p.IsInLine(line2, tolerance);
- }
- Line line = list.Find(match);
- if ((line != null) && !line.SameDirection(line1))
- {
- line = line.Reverse().GetLine();
- }
- return (line ?? line1);
- }
- if (predicate2 == null)
- {
- predicate2 = p => line1.IsInLine(p, tolerance) && line2.IsInLine(p, tolerance);
- }
- Line line7 = list.Find(predicate2);
- if ((line7 != null) && !line7.SameDirection(line1))
- {
- line7 = line7.Reverse().GetLine();
- }
- return (line7 ?? line1);
- }
- /// <summary>
- /// Line1包含line2
- /// </summary>
- /// <param name="line1"></param>
- /// <param name="line2"></param>
- /// <param name="tolerance"></param>
- /// <returns></returns>
- public static bool IsInLine(this Line line1, Line line2, double tolerance = 0.0)
- {
- return (line2.IsContain(line1.StartPoint(), tolerance) && line2.IsContain(line1.EndPoint(), tolerance));
- }
- /// <summary>
- /// 创建直线
- /// </summary>
- /// <param name="pt1"></param>
- /// <param name="pt2"></param>
- /// <returns></returns>
- public static Line CreateBoundExt(XYZ pt1, XYZ pt2)
- {
- if (!pt1.IsEqual(pt2, ExternalDataWrapper.Current.App.ShortCurveTolerance))
- {
- return Line.CreateBound(pt1, pt2);
- }
- return null;
- }
- /// <summary>
- /// 射线转直线
- /// </summary>
- /// <param name="line"></param>
- /// <returns></returns>
- public static Line LineToBound(this Line line)
- {
- if (line.IsBound)
- {
- return line;
- }
- return line.Origin.PointToLine(line.Direction, 1000 * 1000);
- }
- /// <summary>
- /// 创建模型线
- /// </summary>
- /// <param name="line"></param>
- /// <returns></returns>
- public static ModelCurve NewModelCurve(this Line line, SketchPlane sp = null)
- {
- line = line.LineToBound();
- if (sp == null)
- {
- XYZ axis = XYZ.BasisZ;
- XYZ vecX = line.Direction;
- if (axis.IsEqual(vecX) || axis.IsEqual(-vecX))
- {
- axis = XYZ.BasisY;
- }
- XYZ normal = vecX.CrossProduct(vecX.VectorRotate(axis, Math.PI / 2));
- Plane p = RevitApiBaseDll.NewPlane(normal, line.StartPoint());
- sp = SketchPlane.Create(ExternalDataWrapper.Current.Doc, p);
- }
- return ExternalDataWrapper.Current.DocCreater.NewModelCurve(line, sp);
- }
-
- /// <summary>
- /// 返回共平面
- /// </summary>
- public static Plane Plane(this Line line, Curve curve, Document doc)
- {
- Plane plane = null;
- if (curve is Line)
- {
- Line line1 = line.Clone() as Line;
- line1.MakeUnbound();
- Line line2 = curve.Clone() as Line;
- line2.MakeUnbound();
- if (line1.GetIntersections(line2).Count > 0)
- {
- XYZ xVec = line1.Direction;
- XYZ yVec = line2.Direction.CrossProduct(xVec).CrossProduct(xVec);
- plane = RevitApiBaseDll.NewPlane(xVec, yVec, line1.Origin);
- }
- }
- else if (curve is Arc)
- {
- Arc arc = curve as Arc;
- plane = RevitApiBaseDll.NewPlane(arc.Normal, arc.Center);
- if (!(line.Direction.AngleTo(arc.Normal).IsEqual(Math.PI / 2) && plane.IsInside(line.Origin)))
- {
- plane = null;
- }
- }
- return plane;
- }
- /// <summary>
- /// 消除revit的轴网偏差警告
- /// </summary>
- /// <param name="line"></param>
- /// <returns></returns>
- public static Line AdjustLine(this Line line)
- {
- if (line == null)
- {
- return null;
- }
- double tolerance = 0.01;
- XYZ xyz = line.StartPoint();
- XYZ xyz2 = line.EndPoint();
- XYZ vec = line.UnitVector();
- double num2 = Math.PI/4;
- double num3 = Math.PI/2;
- double num4 = vec.QuadrantAngle(null);
- double num5 = num4 % num2;
- double num6 = num4 % num3;
- if (!num6.IsZero(0.0) && !num6.IsEqual(num3, tolerance))
- {
- if (!num5.IsZero(0.0) && !num5.IsEqual(num2, tolerance))
- {
- goto Label_012F;
- }
- for (int i = 0; i < 4; i++)
- {
- double num10 = (num3 * i) + num2;
- if (num4.IsEqual(num10, tolerance))
- {
- num4 = num10;
- break;
- }
- }
- }
- else
- {
- for (int j = 0; j < 5; j++)
- {
- double num8 = num3 * j;
- if (num4.IsEqual(num8, tolerance))
- {
- num4 = num8;
- break;
- }
- }
- xyz2 = xyz + ((XYZ)(XYZ.BasisX.VectorRotate(num4) * line.Length));
- goto Label_012F;
- }
- xyz2 = xyz + ((XYZ)(XYZ.BasisX.VectorRotate(num4) * line.Length));
- Label_012F:
- return Line.CreateBound(xyz, xyz2);
- }
- /// <summary>
- /// 两条线所在直线是否共线
- /// </summary>
- /// <param name="line"></param>
- /// <param name="line2"></param>
- /// <returns></returns>
- public static bool IsSameLine(this Line line, Line line2)
- {
- Line tempLine = line.Clone() as Line;
- tempLine.MakeUnbound();
- return tempLine.Distance(line2.StartPoint()).IsEqual(0) &&
- tempLine.Distance(line2.EndPoint()).IsEqual(0, 0.02);
- }
- /// <summary>
- /// 两条线所在直线是否共线
- /// </summary>
- /// <param name="line"></param>
- /// <param name="line2"></param>
- /// <returns></returns>
- public static bool IsSameLine(this Curve line, Line line2)
- {
- line.MakeUnbound();
- return line.Distance(line2.StartPoint()).IsEqual(0) && line.Distance(line2.EndPoint()).IsEqual(0);
- }
- /// <summary>
- /// 直线打断于一点
- /// </summary>
- /// <returns></returns>
- public static List<Line> BreakOnPoint(this Line line, XYZ pt, double dTol)
- {
- List<Line> list = new List<Line>();
- if (pt.IsEndPoint(line, dTol))
- {
- list.Add(line);
- return list;
- }
- if (pt.IsInLine(line, dTol))
- {
- XYZ second = line.StartPoint();
- XYZ xyz2 = line.EndPoint();
- list.Add(pt.NewLine(second));
- list.Add(pt.NewLine(xyz2));
- return list;
- }
- list.Add(line);
- return list;
- }
- /// <summary>
- /// 相交的类型
- /// </summary>
- /// <param name="line"></param>
- /// <param name="line2"></param>
- /// <param name="dTol"></param>
- /// <returns></returns>
- public static int GetInterCrossStyle(this Line line, Line line2, double dTol = 0)
- {
- int intRtn = 0;
- XYZ pt = line.GetIntersection(line2, dTol);
- if (pt != null)
- {
- List<Line> listLine1 = line.BreakOnPoint(pt, dTol);
- List<Line> listLine2 = line2.BreakOnPoint(pt, dTol);
- if (listLine1.Count == 1 && listLine2.Count == 1 && listLine1[0].Direction.IsEqual(listLine2[0].Direction))
- {
- //一型
- intRtn = 1;
- }
- else
- {
- //2-L型、3-T型、4-十字型
- intRtn = listLine1.Count + listLine2.Count;
- }
- }
- return intRtn;
- }
- /// <summary>
- /// 相交的类型
- /// </summary>
- /// <param name="line"></param>
- /// <param name="line2"></param>
- /// <param name="line3"></param>
- /// <param name="dTol"></param>
- /// <returns></returns>
- public static int GetInterCrossStyle(this Line line, Line line2, Line line3, double dTol = 0)
- {
- int intRtn = 0;
- XYZ pt1 = line.GetIntersection(line2);
- XYZ pt2 = line.GetIntersection(line3);
- if (pt1 != null && pt2 != null && pt1.IsEqual(pt2, dTol))
- {
- List<Line> listLine1 = line.BreakOnPoint(pt1, dTol);
- List<Line> listLine2 = line2.BreakOnPoint(pt1, dTol);
- List<Line> listLine3 = line3.BreakOnPoint(pt1, dTol);
- //3-T型、4-十字型
- intRtn = listLine1.Count + listLine2.Count + listLine3.Count;
- }
- return intRtn;
- }
- /// <summary>
- /// 返回交点
- /// </summary>
- /// <param name="line1"></param>
- /// <param name="line2"></param>
- /// <param name="tolerance"></param>
- /// <returns></returns>
- public static XYZ GetIntersection(this Line line1, Line line2, bool isToUnBound = false)
- {
- XYZ pt = null;
- if (isToUnBound)
- {
- Curve lineClone1 = line1.Clone();
- lineClone1.MakeUnbound();
- Curve lineClone2 = line2.Clone();
- lineClone2.MakeUnbound();
- lineClone1.GetIntersection(lineClone2, out pt, 0);
- }
- else
- {
- line1.GetIntersection(line2, out pt, 0);
- }
- return pt;
- }
- }
- public enum SysLineStyles
- {
- Unknown,
- /// <summary>
- /// 超出
- /// </summary>
- LinesBeyond,
- /// <summary>
- /// 架空线
- /// </summary>
- OverheadLines,
- /// <summary>
- /// 已拆除
- /// </summary>
- DemolishedLines,
- /// <summary>
- /// 隐藏
- /// </summary>
- HiddenLines,
- /// <summary>
- /// 中心线
- /// </summary>
- CenterLines,
- /// <summary>
- /// 宽线
- /// </summary>
- CurvesWideLines,
- /// <summary>
- /// 细线
- /// </summary>
- CurvesThinLines,
- /// <summary>
- /// 线
- /// </summary>
- GenericLines,
- /// <summary>
- /// 隐藏线
- /// </summary>
- LinesHiddenLines,
- /// <summary>
- /// 中粗线
- /// </summary>
- CurvesMediumLines
- }
- }
|