123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- 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);
- }
- /// <summary>
- /// 将线克隆成无边界模式
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="curve"></param>
- /// <returns></returns>
- public static T CloneUnbound<T>(this T curve) where T : Curve
- {
- var clone = curve.Clone();
- if (clone.IsBound)
- {
- clone.MakeUnbound();
- }
- return clone as T;
- }
- /// <summary>
- /// 获取曲线相交点
- /// </summary>
- public static List<XYZ> GetIntersections(this Curve curve1, Curve curve2)
- {
- List<XYZ> result = new List<XYZ>();
- 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;
- }
- /// <summary>
- /// 求交点都用些方法,有问题请讨论
- /// </summary>
- /// <param name="curve1"></param>
- /// <param name="curve2"></param>
- /// <returns></returns>
- public static XYZ GetIntersection(this Curve curve1, Curve curve2)
- {
- List<XYZ> intersections = curve1.GetIntersections(curve2);
- if (intersections != null && intersections.Count > 0)
- {
- return intersections[0];
- }
- return null;
- }
- /// <summary>
- /// 判断点是否在Curve上
- /// </summary>
- 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);
- }
- }
- }
|