Exemple #1
0
        public static NurbsCurve ToRhino(DB.HermiteSpline hermite)
        {
            var nurbsCurve = ToRhino(DB.NurbSpline.Create(hermite));

            nurbsCurve.Domain = new Interval(hermite.GetEndParameter(0), hermite.GetEndParameter(1));
            return(nurbsCurve);
        }
Exemple #2
0
        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.get_EndParameter(0);
            var ep = crv.get_EndParameter(1);

            // get the normalized parameters for trim
            var nsp = Math.Abs(fsp - sp) / fd;
            var nep = Math.Abs(fsp - ep) / fd;

            return(convert.ParameterTrim(nsp, nep));
        }
Exemple #3
0
        private static bool IsLineLikeInternal(Autodesk.Revit.DB.HermiteSpline crv)
        {
            var controlPoints        = crv.ControlPoints;
            var controlPointsAligned = IsLineLikeInternal(controlPoints);

            if (!controlPointsAligned)
            {
                return(false);
            }

            // It's possible for the control points to be straight, but the tangents
            // might not be aligned with the curve.  Let's check the tangents are aligned.
            var line = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(
                controlPoints.First().ToPoint(false),
                controlPoints.Last().ToPoint(false));

            var lineDir = line.Direction.Normalized().ToXyz(false);

            var tangents = crv.Tangents;
            var startTan = tangents.First().Normalize();
            var endTan   = tangents.Last().Normalize();

            return(Math.Abs(startTan.DotProduct(endTan) - 1) < Tolerance &&
                   Math.Abs(lineDir.DotProduct(endTan) - 1) < Tolerance);
        }
Exemple #4
0
        public override FScheme.Value Evaluate(FSharpList <FScheme.Value> args)
        {
            var pts = ((FScheme.Value.List)args[0]).Item;

            hs = null;

            var containers = Utils.SequenceToFSharpList(pts);

            var ctrlPts = new List <XYZ>();

            foreach (FScheme.Value e in containers)
            {
                if (e.IsContainer)
                {
                    XYZ pt = (XYZ)((FScheme.Value.Container)(e)).Item;
                    ctrlPts.Add(pt);
                }
            }
            if (pts.Count() > 0)
            {
                hs = dynRevitSettings.Doc.Application.Application.Create.NewHermiteSpline(ctrlPts, false);
            }

            return(FScheme.Value.NewContainer(hs));
        }
Exemple #5
0
        /// <summary>
        /// Convert a Revit HermiteSpline exactly to a NurbsCurve equivalent
        /// </summary>
        /// <param name="crv"></param>
        /// <returns></returns>
        public static NurbsCurve ConvertExact(Autodesk.Revit.DB.HermiteSpline crv)
        {
            var knots  = Clamp(crv.Parameters.Cast <double>());
            var points = GetNurbsPoints(crv, knots);

            // the resultant nurbs curve is not rational - i.e. it's weights are 1
            var weights = Enumerable.Repeat(1.0, points.Length).ToArray();

            return(NurbsCurve.ByControlPointsWeightsKnots(points, weights, knots, 3));
        }
        public override FScheme.Value Evaluate(FSharpList<FScheme.Value> args)
        {
            var pts = ((FScheme.Value.List)args[0]).Item;

            hs = null;

            var containers = Utils.SequenceToFSharpList(pts);

            var ctrlPts = new List<XYZ>();
            foreach (FScheme.Value e in containers)
            {
                if (e.IsContainer)
                {
                    XYZ pt = (XYZ)((FScheme.Value.Container)(e)).Item;
                    ctrlPts.Add(pt);
                }
            }
            if (pts.Count() > 0)
            {
                hs = dynRevitSettings.Doc.Application.Application.Create.NewHermiteSpline(ctrlPts, false);
            }

            return FScheme.Value.NewContainer(hs);
        }
Exemple #7
0
 public static Curve ToCurve(this DB.HermiteSpline value)
 {
     var rhino = RawDecoder.ToRhino(value); UnitConverter.Scale(rhino, UnitConverter.ToRhinoUnits); return(rhino);
 }
Exemple #8
0
        /// <summary>
        /// Obtain the Nurbs control points from a Hermite Spline
        /// </summary>
        /// <param name="curve"></param>
        /// <param name="nurbsKnots"></param>
        /// <returns></returns>
        internal static Autodesk.DesignScript.Geometry.Point[] GetNurbsPoints(Autodesk.Revit.DB.HermiteSpline curve, double[] nurbsKnots)
        {
            int numKnots  = nurbsKnots.Length;
            int numPoints = numKnots - _cubicOrder;
            var pPoints   = new XYZ[numPoints];

            for (int ii = 0; ii < numPoints; ii++)
            {
                double t = 0.5 * (nurbsKnots[ii] + nurbsKnots[ii + 1]);

                var del = new double[_cubicOrder];
                for (int jj = 1; jj <= _cubicDegree; jj++)
                {
                    del[jj] = nurbsKnots[ii + jj] - t;
                }

                var s = Symmetric(del);

                var psi = new double[_cubicOrder];
                for (int k = 0; k <= _cubicDegree; k++)
                {
                    double top = _power1[k] * _factorial[k] * s[_cubicDegree - k];
                    psi[k] = top / _factorial[_cubicDegree];
                }

                pPoints[ii] = XYZ.Zero;

                var derivTransform = curve.ComputeDerivatives(t, false);

                // this is the expected rep
                var derivs = new[]
                {
                    derivTransform.Origin,
                    derivTransform.BasisX, // 1st deriv
                    derivTransform.BasisY, // 2nd deriv
                    null
                };

                // calculate 3-th derivative
                int low  = 0;
                int high = numPoints + 1;
                int mid  = (low + high) / 2;
                while (t < nurbsKnots[mid] || t >= nurbsKnots[mid + 1])
                {
                    if (t < nurbsKnots[mid])
                    {
                        high = mid;
                    }
                    else
                    {
                        low = mid;
                    }
                    mid = (low + high) / 2;
                }

                // find the span containing t
                double p1 = nurbsKnots[mid];
                double p2 = nurbsKnots[mid + 1];

                // evaluate the point and tangent at the two end points of the span
                var P1R1 = curve.ComputeDerivatives(p1, false);
                var P1   = P1R1.Origin;
                var R1   = P1R1.BasisX;

                var P4R4 = curve.ComputeDerivatives(p2, false);
                var P4   = P4R4.Origin;
                var R4   = P4R4.BasisX;

                // the chord vector from p1 to p2
                var P14 = P1 - P4;
                var R14 = R1 + R4;

                // the span of the region is tk
                double tk = p2 - p1;
                if (tk < 1e-13)
                {
                    tk = 1.0;
                }

                // an approximation of the third derivative
                derivs[3] = P14 * (12.0 / (tk * tk * tk)) + R14 * (6.0 / (tk * tk));

                for (int r = 0; r <= _cubicDegree; r++)
                {
                    int    codegree = _cubicDegree - r;
                    double mul      = _power1[codegree] * psi[codegree];

                    pPoints[ii] = pPoints[ii] + mul * derivs[r];
                }
            }

            return(pPoints.Select(x => x.ToPoint()).ToArray());
        }
Exemple #9
0
 public static NurbsCurve ToRhino(this DB.HermiteSpline hermite) => RawDecoder.ToRhino(hermite);