Grasshopper

algorithmic modeling for Rhino

Hi,

How can I correctly offset a joined curve in C#, probably I do not understand how tolerance value works?

Here I have joined surface edges. Then I just want to offset them. (input just a list of flat rectangle surfaces) But in some cases lines are exploded and in other not. It is also dependent on suface normals direction.

        private List<Curve> CreateGlass(Brep glassSrf, double frameWidth)
        {
            Brep glass = glassSrf;
            Curve[] wireframe = glass.DuplicateEdgeCurves(true);
            Curve[] wireframeJoined = Curve.JoinCurves(wireframe);
 

            List<Curve> outlines = new List<Curve>();

            for (int i = 0; i < wireframeJoined.Length; i++)
            {

                outlines.AddRange(wireframeJoined[i].Offset(Plane.WorldXY, frameWidth, 1, 0));

            }

            return outlines;
        }

Views: 2122

Replies are closed for this discussion.

Replies to This Discussion

This is easy but I can't get the gist of what your input is (flat rectangles == ???).

Post a Rhino file (or better the def + internalized data)

 Here is the code, and there is a printscreen attached what I want to do.

Isuue: When i offset joined boundary curves, they are exploded.

//OUTPUT
        protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
        {

            pManager.AddCurveParameter("Glass", "G", "Glass surfaces", GH_ParamAccess.list);
 
        }

//INPUT

        protected override void SolveInstance(IGH_DataAccess DA)
        {

            Brep glassSrf = new Brep();
            double frameWidth = 1.0;

            // When data cannot be extracted from a parameter, we should abort this method.
            if (!DA.GetData(0, ref glassSrf)) return;
            if (!DA.GetData(1, ref frameWidth)) return;

            List<Curve> glass = CreateGlass(glassSrf, frameWidth);

            for (int i = 0; i < glass.Count; i++)
            {
                DA.SetData(0, glass[i]);
            }

        }

//MAIN FUNCTION

        private List<Curve> CreateGlass(Brep glassSrf, double frameWidth)
        {
            Brep glass = glassSrf;
            Curve[] wireframe = glass.DuplicateEdgeCurves(true);
            Curve[] wireframeJoined = Curve.JoinCurves(wireframe);

            List<Curve> outlines = new List<Curve>();

            for (int i = 0; i < wireframeJoined.Length; i++)
            {
                outlines.AddRange(wireframeJoined[i].Offset(Plane.WorldXY, frameWidth, 0, 0));

               // when I offset joined polyline it becomes exploded.
            }

            return outlines;
        }

Attachments:

If you are sure that your curves always be polylines, you can try to pass each joined curve to PolylineCurve class, which has offset methods, perhaps these will work better.

How to pass correctly pass Curves to PolylineCurves?

PolylineCurve[] pl = PolylineCurve.JoinCurves(wireframe);

This line does not work, stating that:

Cannot implicitly convert type 'Rhino.Geometry.Curve[]' to 'Rhino.Geometry.PolylineCurve[]'. An explicit conversion exists (are you missing a cast?)   

Mmmm, forget that, perhaps the problem is that you're giving CurveOffsetCornerStyle.None in the last parameter of the offset (value 0), try other styles:

Defines enumerated values for all implemented corner styles in curve offsets.

Namespace: Rhino.Geometry
Assembly: RhinoCommon (in RhinoCommon.dll) Version: 5.1.30000.12 (5.0.20693.0)

Collapse imageSyntax

C#
public enum CurveOffsetCornerStyle
Visual Basic
Public Enumeration CurveOffsetCornerStyle

Collapse imageMembers

Member name Value Description
None 0 The dafault value.
Sharp 1 Offsets and extends curves with a straight line until they intersect.
Round 2 Offsets and fillets curves with an arc of radius equal to the offset distance.
Smooth 3 Offsets and connects curves with a smooth (G1 continuity) curve.
Chamfer 4 Offsets and connects curves with a straight line between their endpoints. 

Thanks for your time and help.

This works perfectly:

outlines.AddRange(wireframeJoined[i].Offset(Plane.WorldXY, frameWidth, 0.1, CurveOffsetCornerStyle.Sharp));

Kind Regards,

Petras

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service