How do I simplify/rebuild this NURBS edge into plain 3 segment polyline?

Is dup’ing the edges, simplifying curves and making a new brep the only way?

Before trimming, make sure the trim curve is split at kinks. Afterwards, you can use BrepEdgeList.SplitKinkyEdge.

def test_split_kinky_edges():
    filter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.PolysrfFilter
    rc, objref = Rhino.Input.RhinoGet.GetOneObject("Select surface or polysurface", False, filter)
    if not objref or rc != Rhino.Commands.Result.Success: 
        return
        
    brep = objref.Brep()
    if not brep:
        return
        
    tol = Rhino.RhinoMath.DefaultAngleTolerance
    
    bcopy = brep.DuplicateBrep()
    for i in range(0, bcopy.Edges.Count):
        bcopy.Edges.SplitKinkyEdge(i, tol)
    bcopy.Compact()
    
    sc.doc.Objects.Replace(objref, bcopy)
    sc.doc.Views.Redraw()

– Dale

I’m trimming with a pipe “poly” brep, so no curves involved. But Edges.SplitKinkyEdge did the trick! Thanks Dale!

hi @dale,
sorry for bringing this issue up 2 years after it’s been created.

Does this mean BrepEdgeList.SplitKinkyEdge only works if the trim curve has been split at kinks?

In my case I have input I did not create myself. Sometimes it is really really messy.
So I tried to merge the edges before, because it usually contains a lot of linear edges that actually can be merged. But the result is that e.g. the highlighted edge shoud rather consist of a linear and a curved pard.

SplitKinkyEdge does not work… Acutally I think here a method like SplitAtTangents would be required, but I cannot find any.
Is there any solution to this?

Thanks,
T.

Does what mean?

So what problem are you trying to solve? Perhaps posting a 3dm file might be helpful?

Thanks,

– Dale

@dale
Sorry, I thought it was clear that I was referring to your code.
I also have to admit that in my comment I made my own thought kind of obsolete.
First I thought that splitting brep edges at “kinks” is achieved by BrepEdgeList.SplitKinkyEdge.
What I actually meant is that in this case we are not talking about kinky edges, but we want to split edges at tangents, right?

Here is a file which contains a brep with an edge that acutally consists of two pieces.
It is highlighted with a textdot.

ExampleEdges.3dm (42.0 KB)

Hi @tobias.stoltmann,

I’ll go back to my previous question:

Pretend I know nothing. What problem are you trying to solve?

You’ve posted a valid surface that appears to have some of its edges split. So that is the goal? To merge all edges? To split more edges? Why do you care about any of this?

– Dale

hi @dale,

sorry.
I have to analyze each edges connection to geometry (lines, which are profiles) above these panels (aka. the surface).
Not knowing how “good” my input is (as this is coming from another party) I would like to have a “clean” geometry, meaning that if I analyze a brep edge there is not a second one next to it that actually is colinear. Also it would be very helpful for me that if a curve consists of a linear and curved part these would be two pieces.

Of course I now understand that I might duplicate the surface border, simplify it and process it, but in my eyes it is quite convenient to get this information from the surface/brep, as I would groom this once and I could save it like that for good.

Hope this makes sense. :slight_smile:

Hi @tobias.stoltmann,

You might start off by merging all edges. Rhino has a command for for that - MergeAllEdges. You can also do this via code.

import Rhino
import scriptcontext as sc
import System

def test_merge_all_edges():
    go = Rhino.Input.Custom.GetObject()
    go.SetCommandPrompt("Select Brep")
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Brep
    go.Get()
    if go.CommandResult() != Rhino.Commands.Result.Success:
        return
        
    objref = go.Object(0)
    brep = objref.Brep()
    if brep:
        print("Original edge count: {0}".format(brep.Edges.Count))
        brep_copy = brep.DuplicateBrep()
        ang_tol = System.Math.PI / 180.0
        merge_count = brep_copy.Edges.MergeAllEdges(ang_tol)
        if merge_count > 0:
            print("Merged edge count: {0}".format(brep_copy.Edges.Count))
            sc.doc.Objects.Replace(objref, brep_copy)
            
    sc.doc.Views.Redraw()
    
if __name__ == "__main__":
    test_merge_all_edges()

– Dale

1 Like

Hi @dale,
thanks! This works fine. But there is no way to split brep edges at tangents after doing MergeAllEdges, correct?

Hi @tobias.stoltmann,

RhinoCommon does not have a method to split Brep edge at tangent locations.

However, you might be able to code your own solution. Here is where you might start:

import Rhino

def BrepSplitEdgeAtTangents(brep, edge_index):
    if brep is None:
        return None
    if edge_index < 0 or edge_index >= brep.Edges.Count: 
        return None
        
    curve = brep.Edges[edge_index];
    t0 = curve.Domain.Min;
    t1 = curve.Domain.Max;
    continuity = Rhino.Geometry.Continuity.G2_continuous
    
    params = []
    while t0 < t1:
        rc, t = curve.GetNextDiscontinuity(continuity, t0, t1)
        if rc:
            if t < t1 or (curve.IsClosed and t <= t1):
                parameters.append(t)
            t0 = t
            continue
        else:
            break
          
    if len(params) > 0:
        params.sort()
        params = list(set(params)) 
        rc = brep.DuplicateBrep()
        rc.Edges.SplitEdgeAtParameters(edge_index, params)
        rc.Compact()
        return rc
    return None

Note, I have not tested this…

– Dale