Esempio n. 1
0
        public static Edge ToTopologic(this global::Rhino.Geometry.NurbsCurve nurbsCurve)
        {
            if (nurbsCurve == null)
            {
                return(null);
            }

            int           degree     = nurbsCurve.Degree;
            bool          isPeriodic = nurbsCurve.IsPeriodic;
            bool          isRational = nurbsCurve.IsRational;
            List <double> knots      = nurbsCurve.Knots.ToList();

            knots.Insert(0, knots[0]);
            knots.Add(knots.Last());

            NurbsCurvePointList ghControlPoints = nurbsCurve.Points;
            List <Vertex>       controlPoints   = new List <Vertex>();
            List <double>       weights         = new List <double>();

            for (int i = 0; i < ghControlPoints.Count; ++i)
            {
                controlPoints.Add(ghControlPoints[i].Location.ToTopologic());
                weights.Add(ghControlPoints[i].Weight);
            }

            return(Edge.ByNurbsParameters(controlPoints, weights, knots, isRational, isPeriodic, degree));
        }
Esempio n. 2
0
        public static Edge ToTopologic(this BrepEdge brepEdge)
        {
            if (brepEdge == null)
            {
                return(null);
            }

            global::Rhino.Geometry.NurbsCurve nurbsCurve = brepEdge.ToNurbsCurve();
            return(ToTopologic(nurbsCurve));
        }
Esempio n. 3
0
        public static Edge ToTopologic(this ArcCurve arcCurve)
        {
            if (arcCurve == null)
            {
                return(null);
            }

            global::Rhino.Geometry.NurbsCurve nurbsCurve = arcCurve.ToNurbsCurve();
            return(ToTopologic(nurbsCurve));
        }
Esempio n. 4
0
        public static Topology ToTopologic(this Curve curve)
        {
            if (curve == null)
            {
                return(null);
            }

            LineCurve lineCurve = curve as LineCurve;

            if (lineCurve != null)
            {
                return(lineCurve.Line.ToTopologic());
            }

            global::Rhino.Geometry.NurbsCurve nurbsCurve = curve as global::Rhino.Geometry.NurbsCurve;
            if (nurbsCurve != null)
            {
                return(nurbsCurve.ToTopologic());
            }

            ArcCurve arcCurve = curve as ArcCurve;

            if (arcCurve != null)
            {
                return(arcCurve.ToTopologic());
            }

            BrepEdge brepEdge = curve as BrepEdge;

            if (brepEdge != null)
            {
                return(brepEdge.ToTopologic());
            }

            PolylineCurve ghPolylineCurve = curve as PolylineCurve;

            if (ghPolylineCurve != null)
            {
                return(ghPolylineCurve.ToTopologic());
            }

            PolyCurve ghPolyCurve = curve as PolyCurve;

            if (ghPolyCurve != null)
            {
                return(ghPolyCurve.ToTopologic());
            }

            return(null);
        }
Esempio n. 5
0
        public static Curve ToRhino(this global::Topologic.NurbsCurve nurbsCurve)
        {
            // Based on https://developer.rhino3d.com/api/RhinoCommon/html/P_Rhino_Geometry_NurbsCurve_Knots.htm
            bool           isRational      = nurbsCurve.IsRational;
            int            degree          = nurbsCurve.Degree;
            List <Vertex>  controlVertices = nurbsCurve.ControlVertices;
            List <Point3d> ghControlPoints = new List <Point3d>();

            global::Rhino.Geometry.NurbsCurve ghNurbsCurve = new global::Rhino.Geometry.NurbsCurve(3, isRational, degree + 1, controlVertices.Count);

            int i = 0;

            foreach (Vertex controlVertex in controlVertices)
            {
                Point3d ghControlPoint = ToRhino(controlVertex);
                ghControlPoints.Add(ghControlPoint);
                ghNurbsCurve.Points.SetPoint(i, ghControlPoint);
                ++i;
            }

            List <double> knots = nurbsCurve.Knots;

            knots = knots.GetRange(1, knots.Count - 2);
            i     = 0;
            foreach (double knot in knots)
            {
                ghNurbsCurve.Knots[i] = knot;
                ++i;
            }

            double t0 = nurbsCurve.FirstParameter;
            double t1 = nurbsCurve.LastParameter;

            Curve ghTrimmedNurbsCurve = ghNurbsCurve.Trim(t0, t1);

            String log = "";

            if (ghTrimmedNurbsCurve.IsValidWithLog(out log))
            {
                return(ghTrimmedNurbsCurve);
            }

            throw new Exception("A valid curve cannot be created from this Edge.");
        }