Ejemplo n.º 1
0
        public static bool TryGetEllipse(this Curve curve, out Ellipse ellipse, out Interval interval, double tolerance)
        {
            if (curve.TryGetPlane(out var plane, tolerance))
            {
                if (curve.TryGetArc(plane, out var arc, tolerance))
                {
                    ellipse  = new Ellipse(arc.Plane, arc.Radius, arc.Radius);
                    interval = arc.AngleDomain;
                    return(true);
                }

                if (curve.TryGetEllipse(plane, out ellipse, tolerance))
                {
                    // Curve.TryGetEllipse does not respect curve direction
                    if (plane.Normal.IsParallelTo(ellipse.Plane.Normal) == -1)
                    {
                        ellipse = ellipse.Reverse();
                    }

                    if (curve.IsClosed)
                    {
                        interval = new Interval(0.0, 2.0 * Math.PI);
                        return(true);
                    }
                    else
                    {
                        var nurbsEllipse = ellipse.ToNurbsCurve();
                        if
                        (
                            nurbsEllipse.ClosestPoint(curve.PointAtStart, out var t0, 0.0) &&
                            nurbsEllipse.ClosestPoint(curve.PointAtEnd, out var t1, 0.0)
                        )
                        {
                            interval = new Interval(t0, t1);

                            if (interval.IsDecreasing)
                            {
                                interval.T0 -= Math.PI * 2.0;
                            }

                            return(true);
                        }
                    }
                }
            }

            ellipse  = default;
            interval = Interval.Unset;
            return(false);
        }
Ejemplo n.º 2
0
        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()));
            }
        }
Ejemplo n.º 3
0
        /***************************************************/

        public static void RenderRhinoWires(RHG.Ellipse ellipse, Rhino.Display.DisplayPipeline pipeline, Color bhColour, int thickness)
        {
            pipeline.DrawCurve(ellipse.ToNurbsCurve(), bhColour, thickness);
        }
        public static bool IsClosed(this Ellipse ellipse, Interval interval, double tolerance)
        {
            var nurb = ellipse.ToNurbsCurve();

            return(nurb.PointAt(interval.Min).DistanceTo(nurb.PointAt(interval.Max)) < tolerance);
        }
Ejemplo n.º 5
0
 public Geometry(Rg.Ellipse ellipse)
 {
     curveType = CurveTypes.Ellipse;
     curve     = ellipse.ToNurbsCurve();
 }