public static Polygon ToPolygon(this rg.Curve curve)
 {
     if (curve.IsPolyline() && curve is rg.PolylineCurve pcrv)
     {
         return(pcrv.ToPolyline().ToPolygon());
     }
     return(curve.ToPolyline(0.01, 0.1, 0.1, 100).ToPolyline().ToPolygon());
     // throw new ArgumentException("This curve is not a polygon, conversion will not continue");
 }
Beispiel #2
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());
            }
        }
        public static Polyline ToPolyline(this rg.Curve curve)
        {
            if (curve.IsPolyline() && curve is rg.PolylineCurve pcrv)
            {
                return(pcrv.ToPolyline().ToPolyline());
            }

            if (curve.TryGetPolyline(out rg.Polyline polyline))
            {
                return(polyline.ToPolyline());
            }
            return(curve.ToPolyline(0.01, 0.1, 0.1, 100).ToPolyline().ToPolyline());
        }
Beispiel #4
0
 /// <summary>
 /// Convert a Rhino curve to a Nucleus one
 /// </summary>
 /// <param name="curve"></param>
 /// <returns></returns>
 public static Curve Convert(RC.Curve curve)
 {
     if (curve == null)
     {
         return(null);
     }
     if (curve is RC.LineCurve)
     {
         return(Convert((RC.LineCurve)curve));
     }
     else if (curve.IsLinear())
     {
         return(Convert(new RC.Line(curve.PointAtStart, curve.PointAtEnd)));
     }
     else if (curve.IsPolyline())
     {
         RC.Polyline pLine;
         if (curve.TryGetPolyline(out pLine))
         {
             return(Convert(pLine));
         }
     }
     else if (curve is RC.PolyCurve)
     {
         return(Convert((RC.PolyCurve)curve));
     }
     else if (curve.IsArc())
     {
         RC.Arc arc;
         if (curve.TryGetArc(out arc))
         {
             return(Convert(arc));
         }
     }
     throw new NotImplementedException();
 }
    private Brep[] GetBorderWalls(Curve borderCrv, IEnumerable<Point3d> pts, IEnumerable<Vector3d> nrmls, double dist)
    {
      List<Point3d> ptsOut = new List<Point3d>();
      List<Point3d> ptsIn = new List<Point3d>();
      IEnumerator ptEnum = pts.GetEnumerator();
      IEnumerator nrmlEnum = nrmls.GetEnumerator();
      while ((ptEnum.MoveNext()) && (nrmlEnum.MoveNext()))
      {
        Point3d pt = (Point3d)ptEnum.Current;
        Vector3d nrml = (Vector3d)nrmlEnum.Current;
        Transform mvOut = Transform.Translation(nrml * dist);
        Transform mvIn = Transform.Translation(nrml * -dist);
        Point3d ptOut = new Point3d(pt);
        Point3d ptIn = new Point3d(pt);
        ptOut.Transform(mvOut);
        ptIn.Transform(mvIn);
        ptsOut.Add(ptOut);
        ptsIn.Add(ptIn);
      }

      Curve crvOut;
      Curve crvIn;

      if (borderCrv.IsPolyline())
      {
        crvOut = new PolylineCurve(ptsOut);
        crvIn = new PolylineCurve(ptsIn);
      }
      else
      {
        crvOut = Curve.CreateInterpolatedCurve(ptsOut, 3);
        crvIn = Curve.CreateInterpolatedCurve(ptsIn, 3);
      }
      List<Curve> crvs = new List<Curve>();
      crvs.Add(crvOut);
      crvs.Add(crvIn);
      Brep[] lofts = Brep.CreateFromLoft(crvs, Point3d.Unset, Point3d.Unset, LoftType.Normal, false);

      
      Interval interval = new Interval(0, 1);
      double u, v;
      u = v = 0.05;
      BrepFace loftFace = lofts[0].Faces[0];
      loftFace.SetDomain(0, interval);
      loftFace.SetDomain(1, interval);
      while (u < 1 && v < 1)
      {
        if (loftFace.IsPointOnFace(u, v).Equals(PointFaceRelation.Interior))
        {
          break;
        }
        u += .05;
        v += .05;
      }
      Point3d loftPt = loftFace.PointAt(u, v);
      Vector3d loftNrml = loftFace.NormalAt(u, v);

      Point3d loftPtOut = loftPt;
      Point3d loftPtIn = loftPt;
      loftPtOut.Transform(Transform.Translation(loftNrml));
      loftNrml.Reverse();
      loftPtIn.Transform(Transform.Translation(loftNrml));

      Point3d envPtOut = environment.ClosestPoint(loftPtOut);
      Point3d envPtIn = environment.ClosestPoint(loftPtIn);

      if (loftPtOut.DistanceTo(envPtOut) < loftPtIn.DistanceTo(envPtIn))
      {
        foreach (Brep brep in lofts)
        {
          brep.Flip();
        }
      }

      return lofts;
    }