public static void DrawCurve(RenderDescription description, object obj) { Autodesk.Revit.DB.Curve curve = obj as Autodesk.Revit.DB.Curve; if (curve == null) { return; } IList <XYZ> points = curve.Tessellate(); for (int i = 0; i < points.Count; ++i) { XYZ xyz = points[i]; description.lines.Add(new Point3D(xyz.X, xyz.Y, xyz.Z)); if (i == 0 || i == (points.Count - 1)) { continue; } description.lines.Add(new Point3D(xyz.X, xyz.Y, xyz.Z)); } }
static internal Rhino.Geometry.Curve ToRhino(this Autodesk.Revit.DB.Curve curve) { switch (curve) { case Autodesk.Revit.DB.Line line: { return(line.IsBound ? new Rhino.Geometry.LineCurve(line.GetEndPoint(0).ToRhino(), line.GetEndPoint(1).ToRhino()) : null); } case Autodesk.Revit.DB.Arc arc: { var plane = new Rhino.Geometry.Plane(arc.Center.ToRhino(), new Vector3d(arc.XDirection.ToRhino()), new Vector3d(arc.YDirection.ToRhino())); if (arc.IsBound) { var p0 = arc.GetEndPoint(0).ToRhino(); var p1 = arc.Evaluate(0.5, true).ToRhino(); var p2 = arc.GetEndPoint(1).ToRhino(); return(new Rhino.Geometry.ArcCurve(new Rhino.Geometry.Arc(p0, p1, p2))); } else { return(new Rhino.Geometry.ArcCurve(new Rhino.Geometry.Circle(plane, arc.Radius))); } } case Autodesk.Revit.DB.Ellipse ellipse: { var plane = new Rhino.Geometry.Plane(ellipse.Center.ToRhino(), new Vector3d(ellipse.XDirection.ToRhino()), new Vector3d(ellipse.YDirection.ToRhino())); var e = new Rhino.Geometry.Ellipse(plane, ellipse.RadiusX, ellipse.RadiusY); var n = e.ToNurbsCurve(); if (ellipse.IsBound) { var t0 = Math.IEEERemainder(ellipse.GetEndParameter(0), 2.0 * Math.PI); var t1 = Math.IEEERemainder(ellipse.GetEndParameter(1), 2.0 * Math.PI); return(n.Trim(t0, t1)); } return(n); } case Autodesk.Revit.DB.HermiteSpline hermite: { return(NurbSpline.Create(hermite).ToRhino()); } case Autodesk.Revit.DB.NurbSpline nurb: { var controlPoints = nurb.CtrlPoints; var n = new Rhino.Geometry.NurbsCurve(3, nurb.isRational, nurb.Degree + 1, controlPoints.Count); if (nurb.isRational) { using (var Weights = nurb.Weights) { var weights = Weights.OfType <double>().ToArray(); int index = 0; foreach (var pt in controlPoints) { var w = weights[index]; n.Points.SetPoint(index++, pt.X * w, pt.Y * w, pt.Z * w, w); } } } else { int index = 0; foreach (var pt in controlPoints) { n.Points.SetPoint(index++, pt.X, pt.Y, pt.Z); } } using (var Knots = nurb.Knots) { int index = 0; foreach (var w in Knots.OfType <double>().Skip(1).Take(n.Knots.Count)) { n.Knots[index++] = w; } } return(n); } case Autodesk.Revit.DB.CylindricalHelix helix: // TODO : default: return(new Rhino.Geometry.PolylineCurve(curve.Tessellate().ToRhino())); } }
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); }