Example #1
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 #2
0
        /// <summary>
        /// Returns a Windows Media Path Geometry from a Rhinocommon Arc
        /// </summary>
        /// <param name="input">Rhinocommon Arc</param>
        /// <returns>System Windows Media Path Geometry</returns>
        public static Sm.PathGeometry ToGeometry(this Rg.Arc input)
        {
            Sm.ArcSegment            arc               = new Sm.ArcSegment();
            Sm.PathFigure            figure            = new Sm.PathFigure();
            Sm.PathGeometry          geometry          = new Sm.PathGeometry();
            Sm.PathFigureCollection  figureCollection  = new Sm.PathFigureCollection();
            Sm.PathSegmentCollection segmentCollection = new Sm.PathSegmentCollection();

            figure.StartPoint = input.StartPoint.ToWindowsPoint();

            arc.Point = input.EndPoint.ToWindowsPoint();
            arc.Size  = new Sw.Size(input.Radius, input.Radius);
            if (Rg.Vector3d.VectorAngle(input.Plane.Normal, Rg.Vector3d.ZAxis) > 0)
            {
                arc.SweepDirection = Sm.SweepDirection.Counterclockwise;
            }
            else
            {
                arc.SweepDirection = Sm.SweepDirection.Clockwise;
            }
            arc.IsLargeArc = (input.Angle > Math.PI);

            segmentCollection.Add(arc);
            figure.Segments = segmentCollection;
            figureCollection.Add(figure);
            geometry.Figures = figureCollection;

            return(geometry);
        }
Example #3
0
        /// <summary>
        /// Returns a Windows Media Path from a Rhinocommon Arc
        /// </summary>
        /// <param name="input">Rhinocommon Arc</param>
        /// <returns>System Windows Shapes Path</returns>
        public static Sh.Path ToPath(this Rg.Arc input)
        {
            Sh.Path path = new Sh.Path();

            path.Data = input.ToGeometry();

            return(path);
        }
Example #4
0
        /***************************************************/
        /**** Public Methods  - Curves                  ****/
        /***************************************************/

        public static BHG.Arc FromRhino(this RHG.Arc arc)
        {
            BHG.CoordinateSystem.Cartesian system = arc.Plane.FromRhino();

            return(new BHG.Arc {
                CoordinateSystem = system, StartAngle = arc.StartAngle, EndAngle = arc.EndAngle, Radius = arc.Radius
            });
        }
Example #5
0
        /***************************************************/
        /**** Public Methods  - Curves                  ****/
        /***************************************************/

        public static bool IsEqual(this BHG.Arc bhArc, RHG.Arc rhArc, double tolerance = BHG.Tolerance.Distance)
        {
            if (bhArc == null & rhArc == default(RHG.Arc))
            {
                return(true);
            }

            return(bhArc.CoordinateSystem.IsEqual(rhArc.Plane, tolerance) &&
                   Math.Abs(bhArc.Radius - rhArc.Radius) < tolerance &&
                   Math.Abs(bhArc.StartAngle - rhArc.StartAngle) < tolerance &&
                   Math.Abs(bhArc.EndAngle - rhArc.EndAngle) < tolerance);
        }
Example #6
0
 /// <summary>
 /// Convert a Rhino arc to a Nucleus one
 /// </summary>
 /// <param name="arc"></param>
 /// <returns></returns>
 public static Arc Convert(RC.Arc arc)
 {
     if (arc.IsCircle)
     {
         return(new Arc(Convert(new RC.Circle(arc))));
     }
     else
     {
         return(new Arc(Convert(arc.StartPoint), Convert(arc.MidPoint), Convert(arc.EndPoint)));
     }
     throw new NotImplementedException();
 }
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
        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()));
                var c     = new Rhino.Geometry.Circle(plane, arc.Radius);
                if (arc.IsBound)
                {
                    var a = new Rhino.Geometry.Arc(c, new Interval(arc.GetEndParameter(0), arc.GetEndParameter(1)));
                    return(new Rhino.Geometry.ArcCurve(a));
                }
                else
                {
                    return(new Rhino.Geometry.ArcCurve(c));
                }
            }

            return(null);
        }
Example #11
0
 public static string ToSVG(this Rg.Arc input)
 {
     return("M " + input.StartPoint.ToSVG() + " A " + input.Radius + "," + input.Radius + " " + input.AngleDegrees + " " + Convert.ToInt32(input.Angle > Math.PI) + "," + Convert.ToInt32(!(Rg.Vector3d.VectorAngle(input.Plane.ZAxis, Rg.Vector3d.ZAxis) > 0)) + " " + input.EndPoint.ToSVG() + " ");
 }
Example #12
0
        /***************************************************/
        /**** Public Methods  - Curves                  ****/
        /***************************************************/

        public static void RenderRhinoWires(RHG.Arc arc, Rhino.Display.DisplayPipeline pipeline, Color bhColour, int thickness)
        {
            pipeline.DrawArc(arc, bhColour, thickness);
        }
Example #13
0
        public SilkwormMovement(Dictionary <string, string> Settings, List <Line> lines)
        {
            double eLengthAll = 0;
            double fTimeAll   = 0;

            SilkwormCalculator calc = new SilkwormCalculator(Settings);

            //Core Default Settings for extrusion flow and speed generated in here
            #region Build Silkworm Model from Geometry and Printer Settings


            //Output Holder
            List <SilkwormLine> sLines = new List <SilkwormLine>();

            for (int i = 0; i < lines.Count; i++)
            {
                GH_Line sMove = new GH_Line(lines[i]);
                //if((GH_Line)MInnerArray[j-1] = null){return ;}
                GH_Line sMove_1 = new GH_Line();

                if (i == 0)
                {
                    sMove_1 = new GH_Line(lines[i]);
                }
                else
                {
                    sMove_1 = new GH_Line(lines[i - 1]);
                }


                #region Extrusion Flow Module

                /*
                 * Some Extrusion Calculation Guidelines (from Josef Prusa's Calculator: http://calculator.josefprusa.cz/)
                 *-- WOH smaller than 2.0 produces weak parts
                 * --WOH bigger than 3 decreases the detail of printed part, because of thick line
                 *
                 * layer height (LH)= height of each printed layer above the previous
                 * width over height (WOH) = line width/ layer height
                 * free extrusion diameter (extDia) = nozzle diamter + 0.08mm
                 * line width (LW) = LH * WOH
                 * free extrusion cross section area (freeExt) = (extDia/2)*(extDia/2)*Math.PI
                 * minimal extrusion cross section area for stable extrusion (minExt) = freeExt*0.5
                 * Extruded line cross section area (extLine) = extLine = LW * LH;
                 * Suggested bridge flow-rate multiplier = (freeExt*0.7)/extLine
                 * Predicted smallest feature printable in XY = lineWidth/2
                 * angleHelp = Math.sqrt((lineWidth/2)*(lineWidth/2)+LH*LH)
                 * angleHelp = Math.asin((lineWidth/2)/angleHelp)
                 * Predicted maximim overhang angle = angleHelp * (180/Math.PI)
                 */

                double nozDia = double.Parse(Settings["nozzle_diameter"]);

                double filDia = double.Parse(Settings["filament_diameter"]);

                //Calculate Flow Rate as a Ratio of Filament Diameter to Nozzle Diameter
                double FlM = ((Math.Pow(nozDia / 2, 2) * Math.PI) / (Math.Pow(filDia / 2, 2) * Math.PI));
                //double FlM = 0.66;

                #endregion

                #region Print Feedrate Module
                Line     line   = sMove.Value;
                Line     line_1 = sMove_1.Value;
                Vector3d vecA   = line.Direction;
                Vector3d vecA_1 = line_1.Direction;

                Arc arc = new Rhino.Geometry.Arc(line_1.From, vecA_1, line.To);
                //double vecAngle = Rhino.Geometry.Vector3d.VectorAngle(vecA, vecA_1);
                //Speed on an Arc = sqrt((Accel * Radius) / sqrt(2))


                double accel = double.Parse(Settings["perimeter_acceleration"]);
                double fRate = (
                    Math.Max(
                        Math.Min(
                            Math.Sqrt((accel * arc.Radius) / (Math.Sqrt(2))),
                            double.Parse(Settings["perimeter_speed"])),
                        double.Parse(Settings["min_print_speed"]))
                    * 60);

                //Start speed as perimeter speed
                if (i == 0)
                {
                    fRate = double.Parse(Settings["perimeter_speed"]) * 60;
                }
                #endregion


                sLines.Add(new SilkwormLine(FlM, fRate, line));
            }

            #endregion

            //Property Assignment
            sMovement = sLines;

            Length   = eLengthAll;
            Time     = fTimeAll;
            ZDomain  = new Interval(sLines[0].sLine.FromZ, sLines[sLines.Count - 1].sLine.ToZ);
            complete = true;

            Configuration = Settings;

            //Add Lift Delimiter
            sDelimiter = new Type.Delimiter(
                double.Parse(Settings["retract_lift"]),
                double.Parse(Settings["retract_length"]),
                double.Parse(Settings["retract_restart_extra"]),
                double.Parse(Settings["retract_speed"]),
                double.Parse(Settings["travel_speed"]));
        }
Example #14
0
 public Geometry(Rg.Arc arc)
 {
     curveType = CurveTypes.Arc;
     curve     = arc.ToNurbsCurve();
 }