CurveExtension.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:CurveExtension
  3. * 作者:xulisong
  4. * 创建时间: 2019/6/26 14:14:27
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using Autodesk.Revit.DB;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using SAGA.RevitUtils.Extends;
  14. namespace RevitToJBim.Extension
  15. {
  16. public static class CurveExtension
  17. {
  18. /// <summary>
  19. /// 获取curve偏移后的Polygon信息
  20. /// </summary>
  21. /// <param name="curve"></param>
  22. /// <param name="normal"></param>
  23. /// <param name="offset"></param>
  24. /// <returns></returns>
  25. public static List<XYZ> GetCurvePolygon(this Curve curve, XYZ normal, double offset)
  26. {
  27. List<XYZ> xyzs = new List<XYZ>();
  28. XYZ referenceDirection = normal;
  29. if (curve.IsLine())
  30. {
  31. referenceDirection = normal.CrossProduct((curve as Line).Direction);
  32. }
  33. #region 构建围护线
  34. //从curve1.StartPoint()开始的可以顺序连接的线结构
  35. var curve1 = curve.CreateOffset(offset, referenceDirection);
  36. var curve2 = curve.CreateOffset(-offset, referenceDirection);
  37. var line1 = Line.CreateBound(curve1.EndPoint(), curve2.EndPoint());
  38. var line2 = Line.CreateBound(curve2.StartPoint(), curve1.StartPoint());
  39. //curve2调转方向
  40. curve2 = curve2.CreateReversed();
  41. List<Curve> curves = new List<Curve>();
  42. curves.Add(curve1);
  43. curves.Add(line1);
  44. curves.Add(curve2);
  45. curves.Add(line2);
  46. foreach (Curve useCurve in curves)
  47. {
  48. var points = useCurve.Tessellate();
  49. points.RemoveAt(points.Count - 1);
  50. xyzs.AddRange(points);
  51. }
  52. #endregion
  53. #region 逆时针顺序转化
  54. /*
  55. * //将线结构整理成逆时针形式;
  56. * 如果curve是弧线则使用开始,中间,结束三个点判断
  57. * 如果curve是直线,则使用开始,结束,curve2的开始三个点判断;
  58. *
  59. * 也可以直接使用上面的的点集合取出三个点进行判断
  60. */
  61. List<XYZ> decisionXyzs = new List<XYZ>();
  62. if (curve1.IsLine())
  63. {
  64. decisionXyzs.Add(curve1.StartPoint());
  65. decisionXyzs.Add(curve1.EndPoint());
  66. decisionXyzs.Add(curve2.StartPoint());
  67. }
  68. else if(curve1.IsArc())
  69. {
  70. //找半径大的弧
  71. var useCurve = (curve1 as Arc).Radius > (curve2 as Arc).Radius ? curve1 : curve2;
  72. decisionXyzs.Add(useCurve.StartPoint());
  73. decisionXyzs.Add(useCurve.MiddlePoint());
  74. decisionXyzs.Add(useCurve.EndPoint());
  75. }
  76. if (decisionXyzs.Any())
  77. {
  78. var useDirection = (decisionXyzs[1] - decisionXyzs[0]).CrossProduct(decisionXyzs[2] - decisionXyzs[0]);
  79. var isAnticlockwise = useDirection.IsSameDirection(normal);
  80. if (!isAnticlockwise)
  81. {
  82. xyzs.Reverse();
  83. }
  84. }
  85. #endregion
  86. return xyzs;
  87. }
  88. }
  89. }