/// <summary> /// Set the geometry curve used by the ModelCurve /// </summary> /// <param name="c"></param> protected void InternalSetCurve(Autodesk.Revit.DB.Curve c) { if (!this.InternalCurveElement.GeometryCurve.IsBound && c.IsBound) { c = c.Clone(); c.MakeUnbound(); } setCurveMethod(this.InternalCurveElement, c); }
private static Plane GetPlaneFromCurve(Curve c, bool planarOnly) { //cases to handle //straight line - normal will be inconclusive //find the plane of the curve and generate a sketch plane double period = c.IsBound ? 0.0 : (c.IsCyclic ? c.Period : 1.0); var p0 = c.IsBound ? c.Evaluate(0.0, true) : c.Evaluate(0.0, false); var p1 = c.IsBound ? c.Evaluate(0.5, true) : c.Evaluate(0.25 * period, false); var p2 = c.IsBound ? c.Evaluate(1.0, true) : c.Evaluate(0.5 * period, false); if (c is Line) { var v1 = p1 - p0; var v2 = p2 - p0; XYZ norm = null; //keep old plane computations if (System.Math.Abs(p0.Z - p2.Z) < 0.0001) { norm = XYZ.BasisZ; } else { var p3 = new XYZ(p2.X, p2.Y, p0.Z); var v3 = p3 - p0; norm = v1.CrossProduct(v3); if (norm.IsZeroLength()) { norm = v2.CrossProduct(XYZ.BasisY); } norm = norm.Normalize(); } return(new Plane(norm, p0)); } Autodesk.Revit.DB.CurveLoop cLoop = new Autodesk.Revit.DB.CurveLoop(); cLoop.Append(c.Clone()); if (cLoop.HasPlane()) { return(cLoop.GetPlane()); } if (planarOnly) { return(null); } IList <XYZ> points = c.Tessellate(); List <XYZ> xyzs = new List <XYZ>(); for (int iPoint = 0; iPoint < points.Count; iPoint++) { xyzs.Add(points[iPoint]); } XYZ meanPt; List <XYZ> orderedEigenvectors; PrincipalComponentsAnalysis(xyzs, out meanPt, out orderedEigenvectors); var normal = orderedEigenvectors[0].CrossProduct(orderedEigenvectors[1]); var plane = Document.Application.Create.NewPlane(normal, meanPt); return(plane); }
private static Plane GetPlaneFromCurve(Curve c, bool planarOnly) { //cases to handle //straight line - normal will be inconclusive //find the plane of the curve and generate a sketch plane double period = c.IsBound ? 0.0 : (c.IsCyclic ? c.Period : 1.0); var p0 = c.IsBound ? c.Evaluate(0.0, true) : c.Evaluate(0.0, false); var p1 = c.IsBound ? c.Evaluate(0.5, true) : c.Evaluate(0.25 * period, false); var p2 = c.IsBound ? c.Evaluate(1.0, true) : c.Evaluate(0.5 * period, false); if (c is Line) { var v1 = p1 - p0; var v2 = p2 - p0; XYZ norm = null; //keep old plane computations if (System.Math.Abs(p0.Z - p2.Z) < 0.0001) { norm = XYZ.BasisZ; } else { var p3 = new XYZ(p2.X, p2.Y, p0.Z); var v3 = p3 - p0; norm = v1.CrossProduct(v3); if (norm.IsZeroLength()) { norm = v2.CrossProduct(XYZ.BasisY); } norm = norm.Normalize(); } return new Plane(norm, p0); } Autodesk.Revit.DB.CurveLoop cLoop = new Autodesk.Revit.DB.CurveLoop(); cLoop.Append(c.Clone()); if (cLoop.HasPlane()) { return cLoop.GetPlane(); } if (planarOnly) return null; IList<XYZ> points = c.Tessellate(); List<XYZ> xyzs = new List<XYZ>(); for (int iPoint = 0; iPoint < points.Count; iPoint++) xyzs.Add(points[iPoint]); XYZ meanPt; List<XYZ> orderedEigenvectors; PrincipalComponentsAnalysis(xyzs, out meanPt, out orderedEigenvectors); var normal = orderedEigenvectors[0].CrossProduct(orderedEigenvectors[1]); var plane = Document.Application.Create.NewPlane(normal, meanPt); return plane; }
private static Plane GetPlaneFromCurve(Curve c, bool planarOnly) { //cases to handle //straight line - normal will be inconclusive //find the plane of the curve and generate a sketch plane double period = c.IsBound ? 0.0 : (c.IsCyclic ? c.Period : 1.0); var p0 = c.IsBound ? c.Evaluate(0.0, true) : c.Evaluate(0.0, false); var p1 = c.IsBound ? c.Evaluate(0.5, true) : c.Evaluate(0.25 * period, false); var p2 = c.IsBound ? c.Evaluate(1.0, true) : c.Evaluate(0.5 * period, false); if (c is Line) { var v1 = p1 - p0; var v2 = p2 - p0; XYZ norm = null; //keep old plane computations if (System.Math.Abs(p0.Z - p2.Z) < 0.0001) { norm = XYZ.BasisZ; } else { var p3 = new XYZ(p2.X, p2.Y, p0.Z); var v3 = p3 - p0; norm = v1.CrossProduct(v3); if (norm.IsZeroLength()) { norm = v2.CrossProduct(XYZ.BasisY); } norm = norm.Normalize(); } return new Plane(norm, p0); } Autodesk.Revit.DB.CurveLoop cLoop = new Autodesk.Revit.DB.CurveLoop(); cLoop.Append(c.Clone()); if (cLoop.HasPlane()) { return cLoop.GetPlane(); } if (planarOnly) return null; IList<XYZ> points = c.Tessellate(); List<XYZ> xyzs = new List<XYZ>(); for (int iPoint = 0; iPoint < points.Count; iPoint++) xyzs.Add(points[iPoint]); var bestFitPlane = Autodesk.DesignScript.Geometry.Plane.ByBestFitThroughPoints(xyzs.ToPoints(false)); return bestFitPlane.ToPlane(false); }