Grasshopper

algorithmic modeling for Rhino

Hi all,

I need to unify the directions of a set of curves for a python code.

In order to achieve this in grasshopper, I was usually taking one item from the curves list and using it as a guide curve for the 'Flip Curve' component.

Now I'm trying to do this in python, but it doesn't seem to work properly, sometimes flipping curves that were already in the same direction with the first curve.

This is the code I tried:

import rhinoscriptsyntax as rs

def matchCrv(crv2,crv1):
    flip = False
    if rs.CurveDirectionsMatch(crv2, crv1):
        print 'match'
    else:
        x = rs.ReverseCurve(crv2)
        flip = True
        print x
    return flip

F = []

for i in C:
    tmpflip = matchCrv(i,C[0])
    F.append(tmpflip)

and these are the logs from the 'Flip Curve' and from the code:

*all the curves are closed planar polylines

Only curve #5 had different direction from other curves, but in python curve #3 was flipped too.

Is there anything I'm missing here?

Thanks,

Michael

Views: 1976

Attachments:

Replies to This Discussion

Obviously, it does work if I call 'Flip Curve' component inside python, but I was hoping to avoid importing ghpythonlib:

from ghpythonlib import components as ghcomp
F = ghcomp.FlipCurve(C,C[0])[1]

print F

----------------------------------

[False, False, False, False, False, True]

Works like magic

Thanks a lot Marcus!

I think that this image can describe the poor situation:

but note that the direction is towards the center.

Thanks for the link, definitely interesting talk! In general the concepts weren't new to me, but it was nice to see such clear explanations.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service