123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
-
- using Autodesk.Revit.DB;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using SAGA.RevitUtils.Extends;
- namespace RevitToJBim.Extension
- {
- public static class CurveExtension
- {
-
-
-
-
-
-
-
- public static List<XYZ> GetCurvePolygon(this Curve curve, XYZ normal, double offset)
- {
- List<XYZ> xyzs = new List<XYZ>();
- XYZ referenceDirection = normal;
- if (curve.IsLine())
- {
- referenceDirection = normal.CrossProduct((curve as Line).Direction);
- }
- #region 构建围护线
-
- var curve1 = curve.CreateOffset(offset, referenceDirection);
- var curve2 = curve.CreateOffset(-offset, referenceDirection);
- var line1 = Line.CreateBound(curve1.EndPoint(), curve2.EndPoint());
- var line2 = Line.CreateBound(curve2.StartPoint(), curve1.StartPoint());
-
- curve2 = curve2.CreateReversed();
- List<Curve> curves = new List<Curve>();
- curves.Add(curve1);
- curves.Add(line1);
- curves.Add(curve2);
- curves.Add(line2);
- foreach (Curve useCurve in curves)
- {
- var points = useCurve.Tessellate();
- points.RemoveAt(points.Count - 1);
- xyzs.AddRange(points);
- }
- #endregion
- #region 逆时针顺序转化
-
- List<XYZ> decisionXyzs = new List<XYZ>();
- if (curve1.IsLine())
- {
- decisionXyzs.Add(curve1.StartPoint());
- decisionXyzs.Add(curve1.EndPoint());
- decisionXyzs.Add(curve2.StartPoint());
- }
- else if(curve1.IsArc())
- {
-
- var useCurve = (curve1 as Arc).Radius > (curve2 as Arc).Radius ? curve1 : curve2;
- decisionXyzs.Add(useCurve.StartPoint());
- decisionXyzs.Add(useCurve.MiddlePoint());
- decisionXyzs.Add(useCurve.EndPoint());
- }
- if (decisionXyzs.Any())
- {
- var useDirection = (decisionXyzs[1] - decisionXyzs[0]).CrossProduct(decisionXyzs[2] - decisionXyzs[0]);
- var isAnticlockwise = useDirection.IsSameDirection(normal);
- if (!isAnticlockwise)
- {
- xyzs.Reverse();
- }
- }
- #endregion
- return xyzs;
- }
- }
- }
|