using Autodesk.Revit.DB; using FWindSoft.SystemExtensions; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace FWindSoft.Revit { public static class CurveExtension { public static XYZ StartPoint(this Curve curve) { return curve.GetEndPoint(0); } public static XYZ EndPoint(this Curve curve) { return curve.GetEndPoint(1); } public static Line NewLine(this XYZ start,XYZ end) { return Line.CreateBound(start, end); } public static Line NewUnBoundLine(this XYZ start, XYZ direction) { return Line.CreateUnbound(start, direction); } /// /// 将线克隆成无边界模式 /// /// /// /// public static T CloneUnbound(this T curve) where T : Curve { var clone = curve.Clone(); if (clone.IsBound) { clone.MakeUnbound(); } return clone as T; } /// /// 获取曲线相交点 /// public static List GetIntersections(this Curve curve1, Curve curve2) { List result = new List(); if(curve1 == null || curve2 == null) { return result; } var setResult = curve1.Intersect(curve2, out IntersectionResultArray interResult); if (null != interResult) { foreach (IntersectionResult iResult in interResult) { result.Add(iResult.XYZPoint); } } return result; } /// /// 求交点都用些方法,有问题请讨论 /// /// /// /// public static XYZ GetIntersection(this Curve curve1, Curve curve2) { List intersections = curve1.GetIntersections(curve2); if (intersections != null && intersections.Count > 0) { return intersections[0]; } return null; } /// /// 判断点是否在Curve上 /// public static bool InCurve(this Curve curve, XYZ input, double tolerance = 0) { //当Curve上的,存在多个到input点距离相等,且同时为最短距离是,Distance函数可能出现异常 try { if (curve is Arc arc && arc.Center.IsEqual(input, tolerance)) { return false; } } catch (Exception) { return false; } return curve.Distance(input).IsEqual(0, tolerance); } } }