Example #1
0
 public Floor CurveToSpeckleFloor(RH.Curve curve)
 {
     return(new Floor((ICurve)ConvertToSpeckle(curve))
     {
         units = ModelUnits
     });
 }
Example #2
0
 public Opening CurveToSpeckleOpening(RH.Curve curve)
 {
     return(new Opening((ICurve)ConvertToSpeckle(curve))
     {
         units = ModelUnits
     });
 }
Example #3
0
        public static Sm.DrawingVisual ToGeometryVisual(this Drawing input)
        {
            Sm.DrawingVisual drawings = new Sm.DrawingVisual();

            double scale = input.GetScale();

            Rg.Curve curve = input.Frame.ToNurbsCurve();

            double x0 = input.Frame.Center.X - input.Width / scale / 2;
            double x1 = input.Frame.Center.X + input.Width / scale / 2;

            double y0 = input.Frame.Center.Y - input.Height / scale / 2;
            double y1 = input.Frame.Center.Y + input.Height / scale / 2;

            Rg.Rectangle3d rect = new Rg.Rectangle3d(Rg.Plane.WorldXY, new Rg.Point3d(x0, y0, 0), new Rg.Point3d(x1, y1, 0));

            drawings.Children.Add(new Shape(rect.ToNurbsCurve(), new Wg.Graphic(Wg.Strokes.Transparent, new Wg.Fill(input.Background))).ToVisualDrawing());

            foreach (Shape shape in input.Shapes)
            {
                drawings.Children.Add(shape.ToVisualDrawing());
            }

            Sm.TransformGroup xform = new Sm.TransformGroup();

            double shiftW = (input.Width / scale / 2 - input.Frame.Center.X);
            double shiftH = -(input.Height / scale / 2 + input.Frame.Center.Y);

            xform.Children.Add(new Sm.TranslateTransform(shiftW, shiftH));
            xform.Children.Add(new Sm.ScaleTransform(scale, (-1) * scale));

            drawings.Transform = xform;

            return(drawings);
        }
        /// <summary>
        /// Use 0 as max if you do not want to set it.
        /// </summary>
        /// <param name="min">The minimun number of lines</param>
        /// <param name="max">The maximum, as in GetObject.GetMultiple()</param>
        /// <param name="lines"></param>
        /// <returns>True if the getting supplied the requested lines, false otherwise.</returns>
        public bool Curves(int min, int max, out Curve[] lines)
        {
            GetResult a;
            if (min == 1 && max == 1)
                a = this.Get();
            else
                a = this.GetMultiple(min, max);

            if (a == GetResult.Object)
            {
                if (this.ObjectCount > 0)
                {
                    int realCount = 0;

                    lines = new Curve[this.ObjectCount];
                    for (int i = 0; i < this.ObjectCount; i++)
                    {
                        Curve c = this.Object(i).Curve();
                        if (c != null && c.IsValid)
                        {
                            lines[realCount++] = c;
                        }
                    }
                    Array.Resize(ref lines, realCount);
                    return true;
                }
            }
            lines = null;

            return false;
        }
        // general curve
        public static Model3D RhinoToHelixCurve(Rhino.Geometry.Curve curve, double diameter, int resolution, int resolutiontube, System.Windows.Media.Media3D.Material mat)
        {
            int curvedegree = curve.Degree;
            var modelGroup  = new Model3DGroup();

            Console.WriteLine("BS");

            if (curve.IsLinear()) // if line-like curve
            {
                Console.WriteLine("blabla");
                return(RhinoToHelixLine(curve, diameter, resolutiontube, mat));
            }

            else
            {
                var meshBuilder = new MeshBuilder(false, false);

                //Point3d[] pts = new Point3d[resolution];
                List <Point3D> path = new List <Point3D>();
                //curve.DivideByCount(resolution, true, out pts);
                path.Add(RhinoToHelixPoint(curve.PointAtEnd));
                path.Add(RhinoToHelixPoint(curve.PointAtStart));
                //foreach (Point3d pt in pts)
                //{
                //    path.Add(RhinoToHelixPoint(pt));
                //}
                meshBuilder.AddTube(path, diameter, resolutiontube, false);
                var meshHelix = meshBuilder.ToMesh(true);
                modelGroup.Children.Add(new GeometryModel3D {
                    Geometry = meshHelix, Material = mat, BackMaterial = mat
                });
            }
            return(modelGroup);
        }
Example #6
0
        public static Sm.DrawingGroup ToGeometryGroup(this Drawing input)
        {
            Sm.DrawingGroup drawings = new Sm.DrawingGroup();

            double scale = input.GetScale();

            Rg.Curve curve = input.Frame.ToNurbsCurve();

            double x0 = input.Frame.Center.X - input.Width / scale / 2;
            double x1 = input.Frame.Center.X + input.Width / scale / 2;

            double y0 = input.Frame.Center.Y - input.Height / scale / 2;
            double y1 = input.Frame.Center.Y + input.Height / scale / 2;

            Rg.Rectangle3d rect = new Rg.Rectangle3d(Rg.Plane.WorldXY, new Rg.Point3d(x0, y0, 0), new Rg.Point3d(x1, y1, 0));

            drawings.Children.Add(new Shape(rect.ToNurbsCurve(), new Wg.Graphic(Wg.Strokes.Transparent, new Wg.Fill(input.Background))).ToGeometryDrawing());

            foreach (Shape shape in input.Shapes)
            {
                drawings.Children.Add(shape.ToGeometryDrawing());
            }

            drawings.ClipGeometry = input.Frame.ToPolyline().ToGeometry();

            Sm.TransformGroup xform = new Sm.TransformGroup();

            xform.Children.Add(new Sm.TranslateTransform(input.Frame.Center.X - input.Width / 2, input.Frame.Center.Y - input.Height / 2));
            xform.Children.Add(new Sm.ScaleTransform(1, -1));

            drawings.Transform = xform;

            return(drawings);
        }
Example #7
0
        public SilkwormSegment(Curve curve, int mainSegmentCount, int subSegmentCount, double maxAngleRadians, double maxChordLengthRatio, double maxAspectRatio, double tolerance, double minEdgeLength, double maxEdgeLength, bool keepStartPoint)
        {
            if (curve != null)
            {
                //See if curve can be represented as a polyline already
                if (curve.TryGetPolyline(out Pline))
                {
                    PolylineCurve plinecurve = new PolylineCurve(Pline);
                    //Segments = plinecurve.DuplicateSegments().ToList();
                    Segments = DuplicateSegments(plinecurve);
                }

                //Try to see if conversion will work
                if (curve.ToPolyline(mainSegmentCount, subSegmentCount, maxAngleRadians, maxChordLengthRatio, maxAspectRatio, tolerance, minEdgeLength, maxEdgeLength, keepStartPoint) != null)
                {
                    //Convert
                    PolylineCurve plinec = curve.ToPolyline(mainSegmentCount, subSegmentCount, maxAngleRadians, maxChordLengthRatio, maxAspectRatio, tolerance, minEdgeLength, maxEdgeLength, keepStartPoint);

                    if (plinec.TryGetPolyline(out Pline))
                    {
                        PolylineCurve plinecurve = new PolylineCurve(Pline);
                        //Segments = plinecurve.DuplicateSegments().ToList();
                        Segments = DuplicateSegments(plinecurve);
                    }
                }

            }
        }
Example #8
0
        public SilkwormSegment(Curve curve)
        {
            if (curve != null)
                {
                    //See if curve can be represented as a polyline already
                    if (curve.TryGetPolyline(out Pline))
                    {
                        PolylineCurve plinecurve = new PolylineCurve(Pline);
                        //Segments = plinecurve.DuplicateSegments().ToList();
                        Segments = DuplicateSegments(plinecurve);
                    }

                    //Try to see if conversion will work
                    if (curve.ToPolyline(0, 0, 0.05, 0.1, 0, 0, 0.1, 0, true) != null)
                    {
                    //Convert
                       PolylineCurve plinec = curve.ToPolyline(0, 0, 0.05, 0.1, 0, 0, 0.1, 0, true);

                    if (plinec.TryGetPolyline(out Pline))

                    {
                        PolylineCurve plinecurve = new PolylineCurve(Pline);
                        //Segments = plinecurve.DuplicateSegments().ToList();
                        Segments = DuplicateSegments(plinecurve);

                    }
                    }

            }
        }
Example #9
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 #10
0
 public Beam CurveToSpeckleBeam(RH.Curve curve)
 {
     return(new Beam((ICurve)ConvertToSpeckle(curve))
     {
         units = ModelUnits
     });
 }
Example #11
0
        //addRhinoObject-pointOnObjRef (where curve on)
        //drawPoint,editPointSN in PointMarkers-addSceneNode
        public void resetVariables()
        {
            point_g      = new Geometry.PointMarker(new Vector3());
            currentState = State.READY;

            targetPRhObjID = Guid.Empty;
            //pointOnObjRef = null;
            drawPoint = null;
            projectP  = new Point3d();

            snapPointsList = new List <Point3d>();
            rayCastingObjs = new List <ObjRef>();

            pointsList   = new List <Point3d>();
            pointMarkers = new List <SceneNode>();
            contourCurve = null;
            curvePlane   = new Plane();

            toleranceMax = 100;
            snapDistance = 40;
            isSnap       = false;
            shouldSnap   = false;

            moveControlerOrigin = new Point3d();
            movePlaneRef        = null;
            planeNormal         = new Rhino.Geometry.Vector3d();

            lastTranslate = 0.0f;
        }
Example #12
0
        /// <summary>
        /// Convert a LinearElement to a Rhino Brep
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public static RC.Brep ConvertToBrep(LinearElement element)
        {
            if (element.Geometry is Line)
            {
                return(ConvertToExtrusion(element)?.ToBrep());
            }
            else
            {
                Curve           perimeter = element?.Family?.Profile?.Perimeter;
                CurveCollection voids     = element?.Family?.Profile?.Voids;
                if (perimeter != null && element.Geometry != null)
                {
                    //TODO: Deal with voids!

                    RC.Curve profile = Convert(perimeter);
                    var      cSystem = element.Geometry.LocalCoordinateSystem(0, element.Orientation);

                    RC.Plane startPlane = Convert(cSystem.YZPlane());
                    profile.Transform(RC.Transform.PlaneToPlane(RC.Plane.WorldXY, startPlane));
                    RC.Brep[] breps = RC.Brep.CreateFromSweep(Convert(element.Geometry), profile, false, 0.001); //TODO: Change tolerance
                    if (breps.Length > 0)
                    {
                        return(breps[0]);
                    }
                }
            }
            return(null);
        }
Example #13
0
        /// <summary>
        /// Convert a Nucleus Linear Element to a Rhino Extrusion, if possible
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public static RC.Extrusion ConvertToExtrusion(LinearElement element)
        {
            Curve           perimeter = element?.Family?.Profile?.Perimeter;
            CurveCollection voids     = element?.Family?.Profile?.Voids;

            if (perimeter != null && element.Geometry != null)
            {
                RC.Curve profile = Convert(perimeter);
                var      cSystem = element.Geometry.LocalCoordinateSystem(0, element.Orientation);
                if (element.Geometry is Line)
                {
                    //If a line, create an extrusion:
                    RC.Extrusion ext = new RC.Extrusion();
                    ext.SetPathAndUp(
                        Convert(element.Geometry.EndPoint), Convert(element.Geometry.StartPoint),
                        ConvertVector(cSystem.Z));
                    ext.SetOuterProfile(profile, true);
                    if (voids != null)
                    {
                        var voidCrvs = Convert(voids);
                        foreach (var rCrv in voidCrvs)
                        {
                            ext.AddInnerProfile(rCrv);
                        }
                    }
                    //RC.Surface surface = RC.Extrusion.CreateExtrusion(profile, new RC.Vector3d(Convert(element.End.Position - element.Start.Position)));
                    return(ext);
                }
            }
            return(null);
        }
Example #14
0
 public Column CurveToSpeckleColumn(RH.Curve curve)
 {
     return(new Column((ICurve)ConvertToSpeckle(curve))
     {
         units = ModelUnits
     });
 }
 public FollowPathForceComponent()
   : base(RS.followPathForceName, RS.followPathForceComponentNickname,
       RS.followPathForceDescription, RS.icon_FollowPathForce, RS.followPathForceGuid)
 {
   path = null;
   radius = 5.0;
 }
Example #16
0
        static private Rhino.Geometry.Brep SplitClosedFaces(Rhino.Geometry.Brep brep, double tolerance)
        {
            Brep brepToSplit = null;

            while (brepToSplit != brep && brep != null)
            {
                brep.Standardize();
                brepToSplit = brep;
                foreach (var face in brepToSplit.Faces)
                {
                    face.ShrinkFace(BrepFace.ShrinkDisableSide.ShrinkAllSides);

                    var splittersU = face.IsClosed(0) ? face.TrimAwareIsoCurve(1, face.Domain(0).Mid) : null;
                    var splittersV = face.IsClosed(1) ? face.TrimAwareIsoCurve(0, face.Domain(1).Mid) : null;

                    var splittersULength = (splittersU?.Length).GetValueOrDefault();
                    var splittersVLength = (splittersV?.Length).GetValueOrDefault();
                    var splittersLength  = splittersULength + splittersVLength;
                    if (splittersLength > 0)
                    {
                        var splitters = new Rhino.Geometry.Curve[splittersLength];
                        splittersU?.CopyTo(splitters, 0);
                        splittersV?.CopyTo(splitters, splittersULength);
                        brep = face.Split(splitters, tolerance);

                        if (brep == null || brep.Faces.Count == brepToSplit.Faces.Count)
                        {
                            return(null);
                        }
                    }
                }
            }

            return(brep);
        }
 public void CurveCP(Brep x, Curve y, int V, int U)
 {
     int u = bitmap1.Size.Width;
     int v = bitmap1.Size.Height;
     Graphics g = Graphics.FromImage(bitmap1);
     g.FillRectangle(new SolidBrush(Color.White), 0, 0, u, v);
     System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(Color.Black);
     float step1 = u / U;
     float step2 = v / V;
     for (float i = 25; i < u - 25; i += step1)
     {
         for (float j = 25; j < v - 25; j += step2)
         {
             double Umin = x.Faces[0].Domain(0).Min;
             double Umax = x.Faces[0].Domain(0).Max;
             double Vmin = x.Faces[0].Domain(1).Min;
             double Vmax = x.Faces[0].Domain(1).Max;
             Point3d pos = x.Faces[0].PointAt(i / u * (Umax - Umin) + Umin, j / v * (Vmax - Vmin) + Vmin);
             double t; float R;
             if (y.ClosestPoint(pos, out t, 200))
             {
                 double dis = y.PointAt(t).DistanceTo(pos);
                 dis /= 200;
                 R = (float)(1 / dis * 2);
                 if (R > 40) R = 40;
             }
             else { R = 20; }
             g.FillEllipse(myBrush, i - R, v - j - R, R * 2, R * 2);
         }
     }
     myBrush.Dispose();
     g.Dispose();
 }
            public LineSource(Curve SrcPath, String Code, int el_m, int SrcID, Phase_Regime ph)
                :base(new double[8]{60, 49, 41, 35, 31, 28, 26, 24}, new Point3d(0,0,0), ph, SrcID)
            {
                string type = SrcPath.GetUserString("SourceType");
                
                if (type == "Aircraft (ANCON derived)")
                {
                    double velocity = double.Parse(SrcPath.GetUserString("Velocity"));
                    double delta = double.Parse(SrcPath.GetUserString("delta"));
                    D = new ANCON(delta, velocity);
                }
                else D = new Simple();

                samplespermeter = el_m;
                Curve = SrcPath;

                //Divide curve up in ~equal length segments.
                Samples = Curve.DivideEquidistant(1.0 / (double)samplespermeter);

                Level = Utilities.PachTools.DecodeSourcePower(Code);
                Power = new double[8];
            
                double PowerMod = Curve.GetLength() / (double)Samples.Length;
                for (int oct = 0; oct < 8; oct++) Power[oct] = 1E-12 * Math.Pow(10, .1 * Level[oct]) * PowerMod;
            }
Example #19
0
        static public IList <Brep> ToRhino(this Solid geomObj)
        {
            Solid geomSolid = geomObj as Solid;


            if (null != geomSolid)
            {
                var brepSrfs = new List <Brep>();
                foreach (Face geomFace in geomSolid.Faces)          // get the faces from the solid
                {
                    var facePts = new List <Point3d>();
                    var edgeLp  = geomFace.EdgeLoops.get_Item(0);
                    //int c = 0;
                    foreach (Edge edge in edgeLp)                // get edges from edges
                    {
                        var crv   = edge.AsCurve();
                        XYZ p1    = edge.Evaluate(0); // extract start point
                        var point = p1.ToRhino();     // convert to rhino poing
                        facePts.Add(point);           // save pt to list
                                                      //if (c == geomEdges.Size)
                        //if (c == edgeLp.Size-1)
                        //{
                        //    XYZ p2 = edge.Evaluate(1);                      // get the last point in the edge loop
                        //    var endPt = p2.ToRhino();
                        //    facePts.Add(endPt);
                        //}
                        //    c++;
                    }
                    var lastEdge = edgeLp.get_Item(edgeLp.Size - 1);
                    XYZ p2       = lastEdge.Evaluate(1.0);
                    var endPt    = p2.ToRhino();
                    facePts.Add(endPt);


                    TaskDialog.Show("FacePts nums: ", facePts.Count.ToString());
                    Rhino.Geometry.Curve tempCurve = Rhino.Geometry.Curve.CreateInterpolatedCurve(facePts, 1);
                    if (!tempCurve.IsClosed)
                    {
                        facePts.Add(facePts[0]);
                        tempCurve = Rhino.Geometry.Curve.CreateInterpolatedCurve(facePts, 1);
                    }

                    List <Brep> breps       = new List <Brep>();
                    Brep[]      planarBreps = Brep.CreatePlanarBreps(tempCurve, 0.01);
                    //outVals.Add(planarBreps.Count().ToString());
                    if (planarBreps != null)
                    {
                        brepSrfs.Add(planarBreps[0]);
                    }
                }
                var joinedBrep = Rhino.Geometry.Brep.JoinBreps(brepSrfs, 0.01);
                return(joinedBrep);
                //var ghB = new GH_Brep(joinedBrep);
                //ghbreps.Add(ghB);
            }
            else
            {
                return(new List <Brep>());
            }
        }
Example #20
0
        /// <summary>
        /// Convert a planar Rhino surface to a Nucleus planar region
        /// </summary>
        /// <param name="brep"></param>
        /// <returns></returns>
        public static PlanarRegion ConvertToPlanarRegion(RC.Brep brep, RC.BrepFace face)
        {
            //if (face.IsPlanar())
            //{
            int[]      iEdges = face.AdjacentEdges();
            RC.Curve[] curves = new RC.Curve[iEdges.Length];
            for (int i = 0; i < iEdges.Length; i++)
            {
                RC.BrepEdge bEdge = brep.Edges[i];
                curves[i] = bEdge;
            }
            var joined = RC.Curve.JoinCurves(curves);

            if (joined.Length > 0)
            {
                RC.Curve outer = outerCurve(joined);
                if (outer != null)
                {
                    Curve boundary = Convert(outer);
                    var   result   = new PlanarRegion(boundary);
                    for (int i = 0; i < joined.Length; i++)
                    {
                        if (joined[i] != outer)
                        {
                            Curve voidCrv = Convert(joined[i]);
                            result.Voids.Add(voidCrv);
                        }
                    }
                    return(result);
                }
            }
            //}
            return(null);
        }
Example #21
0
        /// <summary>
        /// Convert a Nucleus extrusion volume to a Rhino one
        /// </summary>
        /// <param name="extrusion"></param>
        /// <returns></returns>
        public static RC.Extrusion Convert(Extrusion extrusion)
        {
            if (extrusion.IsValid)
            {
                Curve           perimeter = extrusion.Profile?.Perimeter;
                CurveCollection voids     = extrusion.Profile?.Voids;
                if (perimeter != null)
                {
                    RC.Curve profile = Convert(perimeter);
                    // var cSystem = new CartesianCoordinateSystem(new Vector(), extrusion.Path);
                    //If a line, create an extrusion:
                    RC.Extrusion ext = new RC.Extrusion();

                    ext.SetPathAndUp(new RC.Point3d(0, 0, 0), Convert(extrusion.Path), RC.Vector3d.YAxis); //TODO: Test!
                    //ConvertVector(cSystem.Z));
                    ext.SetOuterProfile(profile, true);
                    if (voids != null)
                    {
                        var voidCrvs = Convert(voids);
                        foreach (var rCrv in voidCrvs)
                        {
                            ext.AddInnerProfile(rCrv);
                        }
                    }
                    //RC.Surface surface = RC.Extrusion.CreateExtrusion(profile, new RC.Vector3d(Convert(element.End.Position - element.Start.Position)));
                    return(ext);
                }
            }
            return(null);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            GetObject go = new GetObject();

            go.SetCommandPrompt("Select two curves for planar curve containment test");
            go.GeometryFilter          = ObjectType.Curve;
            go.GeometryAttributeFilter = GeometryAttributeFilter.ClosedCurve;
            go.SubObjectSelect         = false;
            go.GetMultiple(2, 2);
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            Rhino.Geometry.Curve curveA = go.Object(0).Curve();
            Rhino.Geometry.Curve curveB = go.Object(1).Curve();
            if (null == curveA || null == curveB)
            {
                return(Result.Failure);
            }

            Plane planeA, planeB;

            if (!curveA.IsPlanar() || !curveA.TryGetPlane(out planeA))
            {
                RhinoApp.WriteLine("Curve A is not planar.");
                return(Result.Success);
            }

            if (!curveB.IsPlanar() || !curveB.TryGetPlane(out planeB))
            {
                RhinoApp.WriteLine("Curve B is not planar.");
                return(Result.Success);
            }

            double            tol = Rhino.RhinoMath.ZeroTolerance;
            RegionContainment rc  = Curve.PlanarClosedCurveRelationship(curveA, curveB, planeA, tol);

            switch (rc)
            {
            case RegionContainment.Disjoint:
                RhinoApp.WriteLine("There is no common area between the two regions.");
                break;

            case RegionContainment.MutualIntersection:
                RhinoApp.WriteLine("The two curves intersect. No full containment relationship exists.");
                break;

            case RegionContainment.AInsideB:
                RhinoApp.WriteLine("Region bounded by curveA (first curve) is inside of curveB (second curve).");
                break;

            case RegionContainment.BInsideA:
                RhinoApp.WriteLine("Region bounded by curveB (second curve) is inside of curveA (first curve).");
                break;
            }

            return(Result.Success);
        }
Example #23
0
 public Shape(Rg.Curve curve, Graphic graphic)
 {
     this.graphic = graphic;
     this.Curves  = new List <Rg.Curve>()
     {
         curve
     };
 }
 /// <summary>
 /// Constructs a new surface of revolution from a generatrix curve and an axis.
 /// <para>This overload accepts a slice start and end angles.</para>
 /// </summary>
 /// <param name="revoluteCurve">A generatrix.</param>
 /// <param name="axisOfRevolution">An axis.</param>
 /// <param name="startAngleRadians">An angle in radias for the start.</param>
 /// <param name="endAngleRadians">An angle in radias for the end.</param>
 /// <returns>A new surface of revolution, or null if any of the inputs is invalid or on error.</returns>
 public static RevSurface Create(Curve revoluteCurve, Line axisOfRevolution, double startAngleRadians, double endAngleRadians)
 {
   IntPtr pConstCurve = revoluteCurve.ConstPointer();
   IntPtr pRevSurface = UnsafeNativeMethods.ON_RevSurface_Create(pConstCurve, ref axisOfRevolution, startAngleRadians, endAngleRadians);
   if (IntPtr.Zero == pRevSurface)
     return null;
   return new RevSurface(pRevSurface, null);
 }
Example #25
0
        /// <summary>
        /// Returns a Windows Media Shapes Bezier Path from a Rhinocommon Curve
        /// </summary>
        /// <param name="input">Rhinocommon Curve</param>
        /// <returns>System Windows Shapes Path</returns>
        public static Sh.Path ToPath(this Rg.Curve input)
        {
            Sh.Path path = new Sh.Path();

            path.Data = input.ToGeometry();

            return(path);
        }
 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");
 }
 public DeviationConduit(Curve curveA, Curve curveB, Point3d minDistPointA, Point3d minDistPointB, Point3d maxDistPointA, Point3d maxDistPointB)
 {
   m_curve_a = curveA;
   m_curve_b = curveB;
   m_min_dist_point_a = minDistPointA;
   m_min_dist_point_b = minDistPointB;
   m_max_dist_point_a = maxDistPointA;
   m_max_dist_point_b = maxDistPointB;
 }
 /// <summary>
 /// Constructs a new sum surface by extruding a curve A along a path B.
 /// </summary>
 /// <param name="curveA">The curve used as extrusion profile.</param>
 /// <param name="curveB">The curve used as path.</param>
 /// <returns>A new sum surface on success; null on failure.</returns>
 public static SumSurface Create(Curve curveA, Curve curveB)
 {
   IntPtr pConstCurveA = curveA.ConstPointer();
   IntPtr pConstCurveB = curveB.ConstPointer();
   IntPtr pSumSurface = UnsafeNativeMethods.ON_SumSurface_Create(pConstCurveA, pConstCurveB);
   if (IntPtr.Zero == pSumSurface)
     return null;
   return new SumSurface(pSumSurface, null);
 }
Example #29
0
        /// <summary>
        /// Replace an existing curve in the Rhino document
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="curve"></param>
        /// <returns></returns>
        public static bool ReplaceCurve(Guid obj, RC.Curve curve)
        {
            bool result = false;

            Writing = true;
            result  = RhinoDoc.ActiveDoc.Objects.Replace(obj, curve);
            Writing = false;
            return(result);
        }
Example #30
0
        private void HandlesReplaceRhinoObject(object sender, RhinoReplaceObjectEventArgs e)
        {
            if (!RhinoOutput.Writing)
            {
                ModelObject mObj = LinkedModelObject(e.ObjectId);
                if (mObj != null)
                {
                    RC.GeometryBase geometry = e.NewRhinoObject.Geometry;

                    if (mObj is Element)
                    {
                        Element        element = (Element)mObj;
                        VertexGeometry vG      = FromRC.Convert(geometry);
                        if (vG == null && geometry is RC.Curve)
                        {
                            // If curve not convertable, reduce to straight line:
                            RC.Curve rCrv = (RC.Curve)geometry;
                            vG = new Line(FromRC.Convert(rCrv.PointAtStart), FromRC.Convert(rCrv.PointAtEnd));
                        }
                        if (vG != null)
                        {
                            _Replacing = true;
                            if (element is LinearElement && vG is Curve)
                            {
                                ((LinearElement)element).ReplaceGeometry((Curve)vG);
                            }
                            else if (element is PanelElement && vG is Surface)
                            {
                                ((PanelElement)element).ReplaceGeometry((Surface)vG);
                            }
                            _Replacing = false;
                            _ReplacedElements.TryAdd(element);
                        }
                    }
                    else if (mObj is Node)
                    {
                        _ReplacedNodesWaitingList[(Node)mObj] = e;

                        /*RC.GeometryBase geometry = e.NewRhinoObject.Geometry;
                         * if (geometry is RC.Point)
                         * {
                         *  Node node = (Node)mObj;
                         *  node.Position = RCtoFB.Convert(((RC.Point)geometry).Location);
                         * }*/
                        /*if (_ObjectReplacedWaitTimer == null)
                         * {
                         *  _ObjectReplacedWaitTimer = new Timer(100);
                         *  _ObjectReplacedWaitTimer.AutoReset = false;
                         *  _ObjectReplacedWaitTimer.Elapsed += ProcessObjectReplacedWaitingList;
                         * }*/
                        //if (!_ObjectReplacedWaitTimer.Enabled)
                    }
                    //if (_ObjectReplacedWaitTimer != null) _ObjectReplacedWaitTimer.Start();
                }
            }
            _LastReplaced = e.ObjectId;
        }
Example #31
0
        public static Curve ToCurve(RG.Curve value, double factor)
        {
            switch (value)
            {
            case RG.NurbsCurve nurbsCurve:
                return(ToCurve(nurbsCurve, factor));

            default:
                return(ToCurve(value.ToNurbsCurve(), factor));
            }
        }
    /// <summary>
    /// Computes an AreaMassProperties for a closed planar curve.
    /// </summary>
    /// <param name="closedPlanarCurve">Curve to measure.</param>
    /// <param name="planarTolerance">absolute tolerance used to insure the closed curve is planar</param>
    /// <returns>The AreaMassProperties for the given curve or null on failure.</returns>
    /// <exception cref="System.ArgumentNullException">When closedPlanarCurve is null.</exception>
    public static AreaMassProperties Compute(Curve closedPlanarCurve, double planarTolerance)
    {
      if (closedPlanarCurve == null)
        throw new ArgumentNullException("closedPlanarCurve");

      const double relativeTolerance = 1.0e-6;
      const double absoluteTolerance = 1.0e-6;
      IntPtr ptr = closedPlanarCurve.ConstPointer();
      IntPtr rc = UnsafeNativeMethods.ON_Curve_AreaMassProperties(ptr, relativeTolerance, absoluteTolerance, planarTolerance);
      return rc == IntPtr.Zero ? null : new AreaMassProperties(rc, false);
    }
Example #33
0
        public static string ToSVG(this Rg.Polyline input)
        {
            Rg.Curve curve  = input.ToNurbsCurve();
            string   output = "M " + input[0].ToSVG();

            for (int i = 1; i < input.Count; i++)
            {
                output += input[i].ToSVG();
            }
            output += " ";
            return(output);
        }
Example #34
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 #35
0
    /// <summary>
    /// Try to fit a circle to two curves using tangent relationships.
    /// </summary>
    /// <param name="c1">First curve to touch.</param>
    /// <param name="c2">Second curve to touch.</param>
    /// <param name="t1">Parameter on first curve close to desired solution.</param>
    /// <param name="t2">Parameter on second curve closet to desired solution.</param>
    /// <returns>Valid circle on success, Circle.Unset on failure.</returns>
    public static Circle TryFitCircleTT(Curve c1, Curve c2, double t1, double t2)
    {
      if (c1 == null) { throw new ArgumentNullException("c1"); }
      if (c2 == null) { throw new ArgumentNullException("c2"); }
      if (!RhinoMath.IsValidDouble(t1)) { throw new ArgumentNullException("t1"); }
      if (!RhinoMath.IsValidDouble(t2)) { throw new ArgumentNullException("t2"); }

      Circle rc = Circle.Unset;
      if (!UnsafeNativeMethods.ON_Circle_TryFitTT(c1.ConstPointer(), c2.ConstPointer(), t1, t2, ref rc))
        rc = Circle.Unset;

      return rc;
    }
Example #36
0
        /***************************************************/

        private static BHG.ICurve ToBHoMTrimCurve(this RHG.Curve curve)
        {
            if (curve.IsArc())
            {
                RHG.Arc arc;
                curve.TryGetArc(out arc);
                return(arc.FromRhino());
            }
            else
            {
                return(curve.FromRhino());
            }
        }
Example #37
0
        /***************************************************/

        public static BHG.SurfaceTrim FromRhino(this RHG.BrepLoop loop)
        {
            BHG.PolyCurve curve2d = new BHG.PolyCurve();
            BHG.PolyCurve curve3d = new BHG.PolyCurve();
            foreach (RHG.BrepTrim trim in loop.Trims)
            {
                curve2d.Curves.Add(trim.ToBHoMTrimCurve());
                RHG.Curve trim3d = loop.Face.Pushup(trim, BHG.Tolerance.Distance);
                curve3d.Curves.Add(trim3d.ToBHoMTrimCurve());
            }

            return(new BHG.SurfaceTrim(curve3d, curve2d));
        }
        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());
        }
Example #39
0
 /// <summary>
 /// Convert a Nucleus polyCurve into a RhinoCommon one
 /// </summary>
 /// <param name="curve"></param>
 /// <returns></returns>
 public static RC.PolyCurve Convert(PolyCurve curve)
 {
     RC.PolyCurve result = new RC.PolyCurve();
     foreach (Curve subCrv in curve.SubCurves)
     {
         RC.Curve rCrv = Convert(subCrv);
         if (rCrv != null)
         {
             result.Append(rCrv);
         }
     }
     return(result);
 }
 public static IfcBoundedCurve ConvertRhinoCommonCurve(DatabaseIfc db, Curve crv)
 {
     double tol = db.Tolerance, angTol = Math.PI / 1800;
     if (crv.IsLinear(tol))
         return new IfcPolyline(new List<IfcCartesianPoint>() { new IfcCartesianPoint(db, crv.PointAtStart), new IfcCartesianPoint(db, crv.PointAtEnd) });
     Plane pln = new Plane();
     if (crv.TryGetPlane(out pln, tol))
     {
         if (Math.Abs(pln.Origin.Z) < tol && pln.ZAxis.IsParallelTo(Vector3d.ZAxis, angTol) != 0)
             return convCurve(db, crv, true);
     }
     return convCurve(db, crv, false);
 }
        private static rg.Brep ExtrudeBrep(rg.Brep brep, rg.Vector3d dir)
        {
            if (dir.IsZero)
            {
                return(brep);
            }
            List <rg.Curve> edgeCurves = new List <rg.Curve>();
            List <rg.Brep>  breps;

            checked
            {
                int num = brep.Edges.Count - 1;
                for (int i = 0; i <= num; i++)
                {
                    if (brep.Edges[i].TrimCount == 1)
                    {
                        rg.Curve item = brep.Edges[i].DuplicateCurve();
                        edgeCurves.Add(item);
                    }
                }
                if (edgeCurves.Count == 0)
                {
                    return(brep);
                }
                breps = new List <rg.Brep>()
                {
                    brep
                };
                int num2 = edgeCurves.Count - 1;
                for (int j = 0; j <= num2; j++)
                {
                    rg.Surface extrusion = Rhino.Compute.SurfaceCompute.CreateExtrusion(edgeCurves[j], dir);
                    if (extrusion != null)
                    {
                        rg.Brep val2 = extrusion.ToBrep();
                        // val2.Faces.SplitKinkyFaces();
                        breps.Add(val2);
                    }
                }
                rg.Brep topFace = brep.DuplicateBrep();
                topFace.Translate(dir);
                breps.Add(topFace);
            }
            rg.Brep[] array = Rhino.Compute.BrepCompute.JoinBreps(breps, 0.0001);
            if (array == null)
            {
                return(brep);
            }
            return(array[0]);
        }
 /// <summary>
 /// Constructs an array of cubic, non-rational beziers that fit a curve to a tolerance.
 /// </summary>
 /// <param name="sourceCurve">A curve to approximate.</param>
 /// <param name="distanceTolerance">
 /// The max fitting error. Use RhinoMath.SqrtEpsilon as a minimum.
 /// </param>
 /// <param name="kinkTolerance">
 /// If the input curve has a g1-discontinuity with angle radian measure
 /// greater than kinkTolerance at some point P, the list of beziers will
 /// also have a kink at P.
 /// </param>
 /// <returns>A new array of bezier curves. The array can be empty and might contain null items.</returns>
 public static BezierCurve[] CreateCubicBeziers(Curve sourceCurve, double distanceTolerance, double kinkTolerance)
 {
   IntPtr pConstCurve = sourceCurve.ConstPointer();
   IntPtr pBezArray = UnsafeNativeMethods.ON_SimpleArray_BezierCurveNew();
   int count = UnsafeNativeMethods.RHC_RhinoMakeCubicBeziers(pConstCurve, pBezArray, distanceTolerance, kinkTolerance);
   BezierCurve[] rc = new BezierCurve[count];
   for (int i = 0; i < count; i++)
   {
     IntPtr ptr = UnsafeNativeMethods.ON_SimpleArray_BezierCurvePtr(pBezArray, i);
     if (ptr != IntPtr.Zero)
       rc[i] = new BezierCurve(ptr);
   }
   UnsafeNativeMethods.ON_SimpleArray_BezierCurveDelete(pBezArray);
   return rc;
 }
Example #43
0
        public static string ToSVG(this Rg.Curve input)
        {
            Rg.NurbsCurve nurbs = input.ToNurbsCurve();
            nurbs.MakePiecewiseBezier(true);
            Rhino.Geometry.BezierCurve[] bezier = Rg.BezierCurve.CreateCubicBeziers(nurbs, 0, 0);

            string output = "M " + input.PointAtStart.ToSVG();

            for (int i = 0; i < bezier.Count(); i++)
            {
                output += " C " + bezier[i].GetControlVertex3d(1).ToSVG() + bezier[i].GetControlVertex3d(2).ToSVG() + bezier[i].GetControlVertex3d(3).ToSVG();
            }
            output += " ";
            return(output);
        }
        public ReactionDiffusion(Mesh x, Curve y)
        {
            Vertice3.CreateCollection(x, out vs);
            Random rnd = new Random();
            for (int i = 0; i < vs.Count; i++)
            {

                Point3d P1 = new Point3d(vs[i].pos.X, vs[i].pos.Y, 0);
                if (y.Contains(P1) == Rhino.Geometry.PointContainment.Inside)
                {
                    vs[i].U = 0.5 * (rnd.NextDouble() * 2);
                    vs[i].V = 0.25 * (rnd.NextDouble() * 2);
                }
            }
        }
Example #45
0
        public static TurtleMesh ExtractTMesh(Curve c)
        {
            var m = new TurtleMesh();
            Polyline pl;
            c.TryGetPolyline(out pl);

            TurtleFace f = new TurtleFace(pl.Count - 1);

            for (int j = 0; j < pl.Count - 1; j++)
            {
                var v = pl[j];
                f.Add(m.VertexCount);
                m.AddVertex(new TurtleVertex((float)v.X, (float)v.Y, (float)v.Z));
            }
            m.AddFace(f);
            return m;
        }
 private void NextintersectParamAndPoint(Curve[] overlapCurves, Point3d[] intersectPoints,
   Curve curve, out double intersectParam, out Point3d intersectPoint)
 {
   var intersect_params_and_points = new Dictionary<double, Point3d>();
   foreach (var point in intersectPoints)
   {
     double curve_param;
     curve.ClosestPoint(point, out curve_param);
     intersect_params_and_points[curve_param] = point;
   }
   foreach (var overlap_curve in overlapCurves)
   {
     intersect_params_and_points[overlap_curve.Domain.Min] = overlap_curve.PointAt(overlap_curve.Domain.Min);
     intersect_params_and_points[overlap_curve.Domain.Max] = overlap_curve.PointAt(overlap_curve.Domain.Max);
   }
   var min_t = intersect_params_and_points.Keys.Min();
   intersectParam = min_t;
   intersectPoint = intersect_params_and_points[intersectParam];
 }
    private static Curve[] GetFeelerCrvs(IParticle particle, double visionDistance,
                                  bool accurate)
    {
      Curve[] feelers;
      if (accurate)
      {
        feelers = new Curve[5];
      }
      else
      {
        feelers = new Curve[1];
      }

      double feelerAngle = RS.HALF_PI;
      //Calculate straight ahead feeler with length visionDistance
      Vector3d feelerVec = particle.Velocity;
      feelerVec.Unitize();
      feelerVec = Vector3d.Multiply(feelerVec, visionDistance);
      feelers[0] = new Line(particle.Position3D, feelerVec).ToNurbsCurve();

      if (!accurate)
      {
        return feelers;
      }

      //Calculate tertiary feelers with length bodySize
      feelerVec = particle.Velocity;
      feelerVec.Unitize();
      Plane rotPln = new Plane(particle.Position3D, particle.Velocity);
      Vector3d rotAxis = rotPln.XAxis;
      feelers[1] = GetFeelerCrv(feelerVec, particle.Position, particle.BodySize, feelerAngle, rotAxis);
      feelers[2] = GetFeelerCrv(feelerVec, particle.Position, particle.BodySize, -feelerAngle, rotAxis);
      rotAxis = rotPln.YAxis;
      feelers[3] = GetFeelerCrv(feelerVec, particle.Position, particle.BodySize, feelerAngle, rotAxis);
      feelers[4] = GetFeelerCrv(feelerVec, particle.Position, particle.BodySize, -feelerAngle, rotAxis);

      return feelers;
    }
 public List<double> RunReactionDiffusion(Mesh x, Curve y, bool z, double iso)
 {
     for (int i = 0; i < vs.Count; i++)
     {
         vs[i].ComputeLaplation3(vs);
     }
     for (int i = 0; i < vs.Count; i++)
     {
         vs[i].ComputeUV1();
     }
     List<double> U2 = new List<double>();
     for (int i = 0; i < vs.Count; i++)
     {
         U2.Add(1 - vs[i].U);
     }
     return U2;
     /*
       A = mc.MeshTopoVerticeDisplay(x, U2);
       if(z) B = tmf.followlines3(x,
       MeshClassLibrary.MeshTopoVerticeConvert.Data_TopoVertices2Vertice(x, U2), iso);
     }
      * */
 }
 /// <summary>
 /// Pulls a 3d curve back to the surface's parameter space.
 /// </summary>
 /// <param name="curve3d">The curve to pull.</param>
 /// <param name="tolerance">
 /// the maximum acceptable 3d distance between from surface(curve_2d(t))
 /// to the locus of points on the surface that are closest to curve_3d.
 /// </param>
 /// <returns>2d curve.</returns>
 public Curve Pullback(Curve curve3d, double tolerance)
 {
   return Pullback(curve3d, tolerance, Interval.Unset);
 }
 /// <summary>
 /// Computes a 3d curve that is the composite of a 2d curve and the surface map.
 /// </summary>
 /// <param name="curve2d">a 2d curve whose image is in the surface's domain.</param>
 /// <param name="tolerance">
 /// the maximum acceptable distance from the returned 3d curve to the image of curve_2d on the surface.
 /// </param>
 /// <returns>3d curve.</returns>
 public Curve Pushup(Curve curve2d, double tolerance)
 {
   return Pushup(curve2d, tolerance, Interval.Unset);
 }
Example #51
0
 /// <summary>
 /// Copies the unmanaged array to a managed counterpart.
 /// </summary>
 /// <returns>The managed array.</returns>
 public Curve[] ToNonConstArray()
 {
   int count = UnsafeNativeMethods.ON_CurveArray_Count(m_ptr);
   if (count < 1)
     return new Curve[0];
   Curve[] rc = new Curve[count];
   for (int i = 0; i < count; i++)
   {
     IntPtr curve = UnsafeNativeMethods.ON_CurveArray_Get(m_ptr, i);
     if (IntPtr.Zero == curve)
       continue;
     rc[i] = GeometryBase.CreateGeometryHelper(curve, null) as Curve;
   }
   return rc;
 }
Example #52
0
 /// <summary>
 /// Projects a Curve onto a collection of Breps along a given direction.
 /// </summary>
 /// <param name="curve">Curve to project.</param>
 /// <param name="breps">Breps to project onto.</param>
 /// <param name="direction">Direction of projection.</param>
 /// <param name="tolerance">Tolerance to use for projection.</param>
 /// <param name="brepIndices">(out) Integers that identify for each resulting curve which Brep it was projected onto.</param>
 /// <returns>An array of projected curves or null if the projection set is empty.</returns>
 public static Curve[] ProjectToBrep(Curve curve, IEnumerable<Brep> breps, Vector3d direction, double tolerance, out int[] brepIndices)
 {
   int[] curveIndices;
   IEnumerable<Curve> crvs = new Curve[] { curve };
   return ProjectToBrep(crvs, breps, direction, tolerance, out curveIndices, out brepIndices);
 }
Example #53
0
 /// <summary>
 /// Projects a Curve onto a collection of Breps along a given direction.
 /// </summary>
 /// <param name="curve">Curve to project.</param>
 /// <param name="breps">Breps to project onto.</param>
 /// <param name="direction">Direction of projection.</param>
 /// <param name="tolerance">Tolerance to use for projection.</param>
 /// <returns>An array of projected curves or empty array if the projection set is empty.</returns>
 public static Curve[] ProjectToBrep(Curve curve, IEnumerable<Brep> breps, Vector3d direction, double tolerance)
 {
   int[] brep_ids;
   return ProjectToBrep(curve, breps, direction, tolerance, out brep_ids);
 }
    //[skipping]
    //  virtual BOOL GetParameterTolerance( // returns tminus < tplus: parameters tminus <= s <= tplus

    /// <summary>
    /// Determines if a 2D curve is iso-parameteric in the parameter space of this surface.
    /// </summary>
    /// <param name="curve">Curve to test.</param>
    /// <param name="curveDomain">Sub domain of the curve.</param>
    /// <returns>IsoStatus flag describing the iso-parametric relationship between the surface and the curve.</returns>
    public IsoStatus IsIsoparametric(Curve curve, Interval curveDomain)
    {
      if (null == curve)
        return IsoStatus.None;
      IntPtr ptr = ConstPointer();
      IntPtr pCurve = curve.ConstPointer();
      int rc = UnsafeNativeMethods.ON_Surface_IsIsoparametric(ptr, pCurve, curveDomain);
      return (IsoStatus)rc;
    }
Example #55
0
 /// <summary>
 /// Projects a curve to a set of meshes using a direction and tolerance.
 /// </summary>
 /// <param name="curve">A curve.</param>
 /// <param name="meshes">A list, an array or any enumerable of meshes.</param>
 /// <param name="direction">A direction vector.</param>
 /// <param name="tolerance">A tolerance value.</param>
 /// <returns>A curve array.</returns>
 public static Curve[] ProjectToMesh(Curve curve, IEnumerable<Mesh> meshes, Vector3d direction, double tolerance)
 {
   Curve[] curves = new Curve[] { curve };
   return ProjectToMesh(curves, meshes, direction, tolerance);
 }
    /// <summary>
    /// Pulls a 3d curve back to the surface's parameter space.
    /// </summary>
    /// <param name="curve3d">A curve.</param>
    /// <param name="tolerance">
    /// the maximum acceptable 3d distance between from surface(curve_2d(t))
    /// to the locus of points on the surface that are closest to curve_3d.
    /// </param>
    /// <param name="curve3dSubdomain">A subdomain of the curve to sample.</param>
    /// <returns>2d curve.</returns>
    public Curve Pullback(Curve curve3d, double tolerance, Interval curve3dSubdomain)
    {
      if (null == curve3d)
        return null;

      IntPtr ptr = ConstPointer();
      IntPtr pCurve3d = curve3d.ConstPointer();
      IntPtr rc = UnsafeNativeMethods.ON_Surface_Pullback(ptr, pCurve3d, tolerance, curve3dSubdomain);
      return GeometryBase.CreateGeometryHelper(rc, null) as Curve;
    }
 /// <summary>
 /// Constructs a surface by extruding a curve to a point.
 /// </summary>
 /// <param name="profile">Profile curve to extrude.</param>
 /// <param name="apexPoint">Apex point of extrusion.</param>
 /// <returns>A Surface on success or null on failure.</returns>
 public static Surface CreateExtrusionToPoint(Curve profile, Point3d apexPoint)
 {
   IntPtr pConstCurve = profile.ConstPointer();
   IntPtr pSurface = UnsafeNativeMethods.RHC_RhinoExtrudeCurveToPoint(pConstCurve, apexPoint);
   if (IntPtr.Zero == pSurface)
     return null;
   // CreateGeometryHelper will create the "actual" surface type (Nurbs, Sum, Rev,...)
   GeometryBase g = GeometryBase.CreateGeometryHelper(pSurface, null);
   Surface rc = g as Surface;
   return rc;
 }
Example #58
0
    /// <summary>
    /// Projects a curve to a set of meshes using a direction and tolerance.
    /// </summary>
    /// <param name="curves">A list, an array or any enumerable of curves.</param>
    /// <param name="meshes">A list, an array or any enumerable of meshes.</param>
    /// <param name="direction">A direction vector.</param>
    /// <param name="tolerance">A tolerance value.</param>
    /// <returns>A curve array.</returns>
    public static Curve[] ProjectToMesh(IEnumerable<Curve> curves, IEnumerable<Mesh> meshes, Vector3d direction, double tolerance)
    {
      foreach (Curve crv in curves)
      {
        if (crv == null)
          throw new ArgumentNullException("curves");
      }
      List<GeometryBase> g = new List<GeometryBase>();
      foreach (Mesh msh in meshes)
      {
        if (msh == null)
          throw new ArgumentNullException("meshes");
        g.Add(msh);
      }

      using (SimpleArrayCurvePointer crv_array = new SimpleArrayCurvePointer(curves))
      using (Runtime.InteropWrappers.SimpleArrayGeometryPointer mesh_array = new Runtime.InteropWrappers.SimpleArrayGeometryPointer(g))
      using (SimpleArrayCurvePointer curves_out = new SimpleArrayCurvePointer())
      {
        IntPtr pCurvesIn = crv_array.ConstPointer();
        IntPtr pMeshes = mesh_array.ConstPointer();
        IntPtr pCurvesOut = curves_out.NonConstPointer();

        Curve[] rc = new Curve[0];
        if (UnsafeNativeMethods.RHC_RhinoProjectCurveToMesh(pMeshes, pCurvesIn, direction, tolerance, pCurvesOut))
          rc = curves_out.ToNonConstArray();
        return rc;
      }
    }
 /// <summary>
 /// Determines if a 2d curve is iso-parameteric in the parameter space of this surface.
 /// </summary>
 /// <param name="curve">Curve to test.</param>
 /// <returns>IsoStatus flag describing the iso-parametric relationship between the surface and the curve.</returns>
 public IsoStatus IsIsoparametric(Curve curve)
 {
   return IsIsoparametric(curve, Interval.Unset);
 }
Example #60
0
    /// <summary>
    /// Projects a Curve onto a Brep along a given direction.
    /// </summary>
    /// <param name="curve">Curve to project.</param>
    /// <param name="brep">Brep to project onto.</param>
    /// <param name="direction">Direction of projection.</param>
    /// <param name="tolerance">Tolerance to use for projection.</param>
    /// <returns>An array of projected curves or empty array if the projection set is empty.</returns>
    public static Curve[] ProjectToBrep(Curve curve, Brep brep, Vector3d direction, double tolerance)
    {
      IntPtr brep_ptr = brep.ConstPointer();
      IntPtr curve_ptr = curve.ConstPointer();

      using (SimpleArrayCurvePointer rc = new SimpleArrayCurvePointer())
      {
        IntPtr rc_ptr = rc.NonConstPointer();
        return UnsafeNativeMethods.RHC_RhinoProjectCurveToBrep(brep_ptr, curve_ptr, direction, tolerance, rc_ptr) ? rc.ToNonConstArray() : new Curve[0];
      }
    }