/// <summary> /// Convert a Revit Arc to a ProtoGeometry Arc /// </summary> /// <param name="crv"></param> /// <returns></returns> private static Autodesk.DesignScript.Geometry.Curve Convert(Autodesk.Revit.DB.Arc crv) { var isCircle = !crv.IsBound || Math.Abs(Math.Abs(crv.GetEndParameter(1) - crv.GetEndParameter(0)) - 2*Math.PI) < 1e-6; if ( isCircle ) { return Circle.ByCenterPointRadiusNormal(crv.Center.ToPoint(), crv.Radius, crv.Normal.ToVector()); } return Arc.ByCenterPointStartPointSweepAngle(crv.Center.ToPoint(), crv.GetEndPoint(0).ToPoint(), (crv.GetEndParameter(1) - crv.GetEndParameter(0))*180/Math.PI, crv.Normal.ToVector()); }
private static Autodesk.DesignScript.Geometry.Curve Convert(Autodesk.Revit.DB.Ellipse crv) { var isComplete = !crv.IsBound || Math.Abs(Math.Abs(crv.GetEndParameter(1) - crv.GetEndParameter(0)) - 2*Math.PI) < 1e-6; if (!isComplete) { var pl = Plane.ByOriginXAxisYAxis(crv.Center.ToPoint(), crv.XDirection.ToVector(), crv.YDirection.ToVector()); var s = crv.GetEndParameter(0).ToDegrees(); var e = crv.GetEndParameter(1).ToDegrees(); return EllipseArc.ByPlaneRadiiStartAngleSweepAngle(pl, crv.RadiusX, crv.RadiusY, s, e - s); } return Autodesk.DesignScript.Geometry.Ellipse.ByOriginVectors(crv.Center.ToPoint(), (crv.XDirection*crv.RadiusX).ToVector(), (crv.YDirection*crv.RadiusY).ToVector()); }
private static Autodesk.DesignScript.Geometry.Curve Convert(Autodesk.Revit.DB.NurbSpline crv) { var convert = NurbsCurve.ByControlPointsWeightsKnots(crv.CtrlPoints.Select(x => x.ToPoint(false)).ToArray(), crv.Weights.Cast<double>().ToArray(), crv.Knots.Cast<double>().ToArray(), crv.Degree ); if (!crv.IsBound) return convert; // bound the curve parametric range // we first get the full parametric domain from the knots // note that some knots be negative and the domain may appear reversed var parms = crv.Knots.Cast<double>().ToList(); var fsp = parms.First(); var fep = parms.Last(); // obtain the full domain var fd = Math.Abs(fsp - fep); // these are the start and end parameters of the bound curve var sp = crv.GetEndParameter(0); var ep = crv.GetEndParameter(1); // get the normalized parameters for trim var nsp = Math.Abs(fsp - sp) / fd; var nep = Math.Abs(fsp - ep) / fd; // if there's no trimming to do, avoid it if (Math.Abs(nsp) < 1e-6 && Math.Abs(1 - nep) < 1e-6) return convert; return convert.ParameterTrim(nsp, nep); }
private static Autodesk.DesignScript.Geometry.Curve Convert(Autodesk.Revit.DB.Ellipse crv) { var isFullEllipse = !crv.IsBound || Math.Abs(Math.Abs(crv.GetEndParameter(1) - crv.GetEndParameter(0)) - 2*Math.PI) < 1e-6; if (isFullEllipse) { return Autodesk.DesignScript.Geometry.Ellipse.ByOriginVectors( crv.Center.ToPoint(false), (crv.XDirection*crv.RadiusX).ToVector(false), (crv.YDirection*crv.RadiusY).ToVector(false)); } // We need to define the major and minor axis as the curve // will be trimmed starting from the major axis (not the xaxis) var major = Math.Max(crv.RadiusX, crv.RadiusY); var minor = Math.Min(crv.RadiusX, crv.RadiusY); Vector majorAxis; Vector minorAxis; double startParam; var span = Math.Abs( crv.GetEndParameter(0) - crv.GetEndParameter(1)).ToDegrees(); if (crv.RadiusX > crv.RadiusY) { majorAxis = crv.XDirection.ToVector(); minorAxis = crv.YDirection.ToVector(); startParam = crv.GetEndParameter(0).ToDegrees(); } else { majorAxis = crv.YDirection.ToVector().Reverse(); minorAxis = crv.XDirection.ToVector(); startParam = crv.GetEndParameter(0).ToDegrees() + 90; } var pl = Plane.ByOriginXAxisYAxis(crv.Center.ToPoint(false), majorAxis, minorAxis); return EllipseArc.ByPlaneRadiiStartAngleSweepAngle(pl, major, minor, startParam, span); }
private static Autodesk.DesignScript.Geometry.Curve Convert(Autodesk.Revit.DB.HermiteSpline crv) { var convert = HermiteToNurbs.ConvertExact(crv); if (!crv.IsBound) return convert; // bound the curve parametric range // we first get the full parametric domain from the parameters // note that some knots be negative and the domain may appear reversed var parms = crv.Parameters.Cast<double>().ToList(); var fsp = parms.First(); var fep = parms.Last(); // obtain the full domain var fd = Math.Abs(fsp - fep); // these are the start and end parameters of the bound curve var sp = crv.GetEndParameter(0); var ep = crv.GetEndParameter(1); // get the normalized parameters for trim var nsp = Math.Abs(fsp - sp)/fd; var nep = Math.Abs(fsp - ep)/fd; // if there's no trimming to do, avoid it if (Math.Abs(nsp) < 1e-6 && Math.Abs(1 - nep) < 1e-6) return convert; return convert.ParameterTrim(nsp, nep); }