Example #1
0
        /***************************************************/

        public static BHG.ICurve FromRhino(this RHG.NurbsCurve rCurve)
        {
            if (rCurve == null)
            {
                return(null);
            }

            if (rCurve.IsPolyline())
            {
                RHG.Polyline polyline;
                rCurve.TryGetPolyline(out polyline);
                return(polyline.FromRhino());
            }

            if (rCurve.IsClosed && rCurve.IsEllipse())
            {
                RHG.Ellipse ellipse = new RHG.Ellipse();
                rCurve.TryGetEllipse(out ellipse);
                return(ellipse.FromRhino());
            }

            IEnumerable <RHG.ControlPoint> rPoints = rCurve.Points;
            List <double> knots = rCurve.Knots.ToList();

            return(new BHG.NurbsCurve
            {
                ControlPoints = rPoints.Select(x => x.FromRhino()).ToList(),
                Weights = rPoints.Select(x => x.Weight).ToList(),
                Knots = knots
            });
        }
Example #2
0
        public static string ToSVG(this Rg.Ellipse input)
        {
            Rg.Vector3d axisX = input.Plane.XAxis;
            axisX.Unitize();
            axisX = axisX * input.Radius1;

            Rg.Vector3d axisY = input.Plane.YAxis;
            axisY.Unitize();
            axisY = axisY * input.Radius2;

            Rg.Point3d A = input.Plane.Origin + axisX;
            Rg.Point3d B = input.Plane.Origin + axisY;

            axisX.Reverse();
            axisY.Reverse();

            Rg.Point3d C = input.Plane.Origin + axisX;
            Rg.Point3d D = input.Plane.Origin + axisY;

            double radians = Rg.Vector3d.VectorAngle(input.Plane.YAxis, Rg.Vector3d.YAxis, Rg.Plane.WorldXY);
            double degrees = 180.0 - (radians / Math.PI) * 180.0;
            int    flip    = Convert.ToInt32(!(Rg.Vector3d.VectorAngle(input.Plane.ZAxis, Rg.Vector3d.ZAxis) > 1));

            return("M " + A.ToSVG()
                   + " A " + input.Radius1 + ", " + input.Radius2 + " " + degrees + " 0," + flip + " " + B.ToSVG()
                   + " A " + input.Radius1 + ", " + input.Radius2 + " " + degrees + " 0," + flip + " " + C.ToSVG()
                   + " A " + input.Radius1 + ", " + input.Radius2 + " " + degrees + " 0," + flip + " " + D.ToSVG()
                   + " A " + input.Radius1 + ", " + input.Radius2 + " " + degrees + " 0," + flip + " " + A.ToSVG());
        }
Example #3
0
        private void SetCurveType(Rg.Curve curve)
        {
            Rg.Circle   R = new Rg.Circle();
            Rg.Arc      A = new Rg.Arc();
            Rg.Ellipse  S = new Rg.Ellipse();
            Rg.Polyline P = new Rg.Polyline();

            if (curve.TryGetCircle(out R))
            {
                curveType = CurveTypes.Circle;
            }
            else if (curve.TryGetArc(out A))
            {
                curveType = CurveTypes.Arc;
            }
            else if (curve.TryGetEllipse(out S))
            {
                curveType = CurveTypes.Ellipse;
            }
            else if (curve.IsLinear())
            {
                curveType = CurveTypes.Line;
            }
            else if (curve.TryGetPolyline(out P))
            {
                curveType = CurveTypes.Polyline;
            }
            else
            {
                curveType = CurveTypes.Spline;
            }
        }
Example #4
0
        /// <summary>
        /// Returns a Windows Shapes Path from a Rhinocommon Ellipse
        /// </summary>
        /// <param name="input">Rhinocommon Ellipse</param>
        /// <returns>System Windows Shapes Path</returns>
        public static Sh.Path ToPath(this Rg.Ellipse input)
        {
            Sh.Path path = new Sh.Path();

            path.Data = input.ToGeometry();

            return(path);
        }
Example #5
0
        /// <summary>
        /// Returns a Windows Media Ellipse from a Rhinocommon Ellipse
        /// </summary>
        /// <param name="input">Rhinocommon Ellipse</param>
        /// <returns>System Windows Media Ellipse</returns>
        public static Sm.EllipseGeometry ToGeometry(this Rg.Ellipse input)
        {
            Sw.Point origin = input.Plane.Origin.ToWindowsPoint();
            double   angle  = Rg.Vector3d.VectorAngle(Rg.Vector3d.YAxis, input.Plane.YAxis, Rg.Plane.WorldXY);

            angle = angle / System.Math.PI * 180;
            Sm.Transform xform = new Sm.RotateTransform(angle, origin.X, origin.Y);

            return(new Sm.EllipseGeometry(origin, input.Radius1, input.Radius2, xform));
        }
Example #6
0
        /***************************************************/

        public static BHG.Ellipse FromRhino(this RHG.Ellipse ellipse)
        {
            return(new BHG.Ellipse
            {
                Centre = ellipse.Plane.Origin.FromRhino(),
                Axis1 = ellipse.Plane.XAxis.FromRhino(),
                Axis2 = ellipse.Plane.YAxis.FromRhino(),
                Radius1 = ellipse.Radius1,
                Radius2 = ellipse.Radius2
            });
        }
Example #7
0
        /***************************************************/

        public static BHG.ICurve FromRhino(this RHG.Curve rCurve)
        {
            if (rCurve == null)
            {
                return(null);
            }

            Type curveType = rCurve.GetType();

            if (rCurve.IsLinear() && rCurve.SpanCount < 2)
            {
                return(new BHG.Line {
                    Start = rCurve.PointAtStart.FromRhino(), End = rCurve.PointAtEnd.FromRhino(), Infinite = false
                });
            }
            if (rCurve.IsCircle())
            {
                RHG.Circle circle = new RHG.Circle();
                rCurve.TryGetCircle(out circle);
                return(circle.FromRhino());
            }
            else if (rCurve.IsArc() || typeof(RHG.ArcCurve).IsAssignableFrom(curveType))
            {
                RHG.Arc arc = new RHG.Arc();
                rCurve.TryGetArc(out arc);
                return(arc.FromRhino());
            }
            else if (rCurve.IsPolyline() || typeof(RHG.PolylineCurve).IsAssignableFrom(curveType))
            {
                RHG.Polyline polyline = new RHG.Polyline();
                rCurve.TryGetPolyline(out polyline);
                return(polyline.FromRhino());
            }
            else if (rCurve.IsClosed && rCurve.IsEllipse())
            {
                RHG.Ellipse ellipse = new RHG.Ellipse();
                rCurve.TryGetEllipse(out ellipse);
                return(ellipse.FromRhino());
            }
            else if (rCurve is RHG.NurbsCurve)
            {
                return(((RHG.NurbsCurve)rCurve).FromRhino());
            }
            else if (rCurve is RHG.PolyCurve)
            {
                return(((RHG.PolyCurve)rCurve).FromRhino());  //The test of IsPolyline above is very important to make sure we can cast to PolyCurve here
            }
            else
            {
                return((rCurve.ToNurbsCurve()).FromRhino());
            }
        }
Example #8
0
        public static string ToSVG(this Hp.Geometry input)
        {
            string path = string.Empty;

            switch (input.CurveType)
            {
            case Geometry.CurveTypes.Arc:
                Rg.Arc arc = new Rg.Arc();
                input.Curve.TryGetArc(out arc);
                path = arc.ToSVG();
                break;

            case Geometry.CurveTypes.Circle:
                Rg.Circle circle = new Rg.Circle();
                input.Curve.TryGetCircle(out circle);
                path = circle.ToSVG();
                break;

            case Geometry.CurveTypes.Ellipse:
                Rg.Ellipse ellipse = new Rg.Ellipse();
                input.Curve.TryGetEllipse(out ellipse);
                path = ellipse.ToSVG();
                break;

            case Geometry.CurveTypes.Line:
                Rg.Line line = new Rg.Line(input.Curve.PointAtStart, input.Curve.PointAtEnd);
                path = line.ToSVG();
                break;

            case Geometry.CurveTypes.Polyline:
                Rg.Polyline polyline = new Rg.Polyline();
                input.Curve.TryGetPolyline(out polyline);
                path = polyline.ToSVG();
                break;

            case Geometry.CurveTypes.Rectangle:
                Rg.Polyline pline = new Rg.Polyline();
                input.Curve.TryGetPolyline(out pline);
                path = pline.ToSVG();
                break;

            default:
                path = input.Curve.ToSVG();
                break;
            }

            return(path);
        }
Example #9
0
        public static Sm.Geometry ToGeometry(this Geometry input)
        {
            Sm.Geometry geometry = null;
            switch (input.CurveType)
            {
            case Geometry.CurveTypes.Arc:
                Rg.Arc arc = new Rg.Arc();
                input.Curve.TryGetArc(out arc);
                geometry = arc.ToGeometry();
                break;

            case Geometry.CurveTypes.Circle:
                Rg.Circle circle = new Rg.Circle();
                input.Curve.TryGetCircle(out circle);
                geometry = circle.ToGeometry();
                break;

            case Geometry.CurveTypes.Ellipse:
                Rg.Ellipse ellipse = new Rg.Ellipse();
                input.Curve.TryGetEllipse(out ellipse);
                geometry = ellipse.ToGeometry();
                break;

            case Geometry.CurveTypes.Line:
                Rg.Line line = new Rg.Line(input.Curve.PointAtStart, input.Curve.PointAtEnd);
                geometry = line.ToGeometry();
                break;

            case Geometry.CurveTypes.Polyline:
                Rg.Polyline polyline = new Rg.Polyline();
                input.Curve.TryGetPolyline(out polyline);
                geometry = polyline.ToGeometry();
                break;

            case Geometry.CurveTypes.Rectangle:
                Rg.Polyline pline = new Rg.Polyline();
                input.Curve.TryGetPolyline(out pline);
                Rg.Rectangle3d rectangle = new Rg.Rectangle3d(Rg.Plane.WorldXY, pline[0], pline[2]);
                geometry = rectangle.ToGeometry();
                break;

            default:
                geometry = input.Curve.ToGeometry();
                break;
            }
            return(geometry);
        }
Example #10
0
 /// <summary>
 /// Try to convert this curve into an Ellipse using a custom tolerance.
 /// </summary>
 /// <param name="plane">Plane in which the comparison is performed.</param>
 /// <param name="ellipse">On success, the Ellipse will be filled in.</param>
 /// <param name="tolerance">Tolerance to use when checking.</param>
 /// <returns>true if the curve could be converted into an Ellipse within the given plane.</returns>
 public bool TryGetEllipse(Plane plane, out Ellipse ellipse, double tolerance)
 {
   ellipse = new Ellipse();
   IntPtr ptr = ConstPointer();
   return UnsafeNativeMethods.ON_Curve_IsEllipse(ptr, idxIgnoreNone, ref plane, ref ellipse, tolerance);
 }
Example #11
0
 /// <summary>
 /// Try to convert this curve into an Ellipse within RhinoMath.ZeroTolerance.
 /// </summary>
 /// <param name="plane">Plane in which the comparison is performed.</param>
 /// <param name="ellipse">On success, the Ellipse will be filled in.</param>
 /// <returns>true if the curve could be converted into an Ellipse within the given plane.</returns>
 public bool TryGetEllipse(Plane plane, out Ellipse ellipse)
 {
   return TryGetEllipse(plane, out ellipse, RhinoMath.ZeroTolerance);
 }
Example #12
0
 /// <summary>
 /// Test a curve to see if it can be represented by an ellipse within a given tolerance.
 /// </summary>
 /// <param name="tolerance">Tolerance to use for checking.</param>
 /// <returns>
 /// true if the Curve can be represented by an ellipse within tolerance.
 /// </returns>
 public bool IsEllipse(double tolerance)
 {
   Plane plane = Plane.WorldXY;
   Ellipse ellipse = new Ellipse();
   IntPtr ptr = ConstPointer();
   return UnsafeNativeMethods.ON_Curve_IsEllipse(ptr, idxIgnorePlaneArcOrEllipse, ref plane, ref ellipse, tolerance);
 }
 public bool SetFromEllipse(Ellipse ellipse)
 {
   IntPtr pThis = NonConstPointer();
   return UnsafeNativeMethods.CRhinoGumball_SetFromEllipse(pThis, ref ellipse);
 }
Example #14
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()));
            }
        }
Example #15
0
        /***************************************************/

        public static void RenderRhinoWires(RHG.Ellipse ellipse, Rhino.Display.DisplayPipeline pipeline, Color bhColour, int thickness)
        {
            pipeline.DrawCurve(ellipse.ToNurbsCurve(), bhColour, thickness);
        }
Example #16
0
 public Geometry(Rg.Ellipse ellipse)
 {
     curveType = CurveTypes.Ellipse;
     curve     = ellipse.ToNurbsCurve();
 }