CreateFilletCurves returns empty array


#1

Hello,
Can someone Please tell me what is wrong with this chunk of code?

from Rhino import *
from Rhino.Commands import *
from Rhino.Geometry import *
from Rhino.Input import *
from Rhino.DocObjects import *
from Rhino.Input.Custom import *
from scriptcontext import doc
import rhinoscriptsyntax as rs
import math

def BowProfFillet(StemCrv,KeelCrv):
    Crv1 = rs.coercecurve(StemCrv)
    Pt1 = rs.CurveStartPoint(StemCrv)
    Crv2 = rs.coercecurve(KeelCrv)
    Pt2 = rs.CurveStartPoint(KeelCrv)
    FilletCrvs = Curve.CreateFilletCurves(Crv1,Pt1,Crv2,Pt2,1,
        True,True,True,0.001, 0.01)
    doc.Objects.AddCurve(FilletCrvs[0])

StemCrv and KeelCrv are GUIDs of the two curves I am trying to fillet, but I get an empty array back from Curve.CreateFilletCurves(). Is there something I’m am doing wrong? I found the example code online that uses Curve.CreateFilletCurves() and can get it to work, but when I try to implement it in my own code I get nothing.

Thanks


#2

Can you post the curves? Does it work if you do it manually (Rhino Fillet command) with your curves?

Edit - I tested your code here and it does seem to work on the case of a couple of lines…

–Mitch


#3

Here is the whole code.

from Rhino import *
from Rhino.Commands import *
from Rhino.Geometry import *
from Rhino.Input import *
from Rhino.DocObjects import *
from Rhino.Input.Custom import *
from scriptcontext import doc
import rhinoscriptsyntax as rs
import math

__commandname__ = "GenHull"

def StemLine(Input):
    BaseLinePt = (-Input['Origin_Height']/(math.tan(Input['Bow_Rake_Angle']*math.pi/180.0)),0.0,0.0)
    BowPt = ((Input['Depth']-Input['Origin_Height'])/(math.tan(Input['Bow_Rake_Angle']*math.pi/180.0)),0.0,Input['Depth'])
    crvpts = [BowPt,BaseLinePt]
    StemCrv = rs.AddCurve(crvpts,degree=3)
    return StemCrv

def KeelLine(Input,StemCrv):
    KeelStrtPt = rs.CurveEndPoint(StemCrv)
    FwdPt = rs.CurveStartPoint(StemCrv)
    KeelFlatEndPt = (Input['Midbody_Hull_XPos'],0.0,0.0)
    SternPt2 = (FwdPt.X-Input['LOA'],0.0,Input['Prop_Clearance'])
    SternRun = -math.cos(Input['Stern_Rise_Angle']*math.pi/180.0)
    SternRise = math.sin(Input['Stern_Rise_Angle']*math.pi/180.0)
    SternPt1 = (SternPt2[0]-SternRun*Input['Stern_Length'],0.0,SternPt2[2]-SternRise*Input['Stern_Length'])
    KeelCrv1Pts = [KeelStrtPt,KeelFlatEndPt]
    KeelCrv2Pts = [KeelFlatEndPt,SternPt1]
    KeelCrv3Pts = [SternPt1,SternPt2]
    KeelCrv1 = rs.AddCurve(KeelCrv1Pts,degree = 1)
    KeelCrv2 = rs.AddInterpCurve(KeelCrv2Pts,degree = 3,knotstyle=2,start_tangent=(-1.0,0.0,0.0),end_tangent=(SternRun,0.0,SternRise))
    KeelCrv3 = rs.AddCurve(KeelCrv3Pts,degree = 1)
    KeelCrv = rs.JoinCurves([KeelCrv1,KeelCrv2,KeelCrv3],delete_input=True)
    
    return KeelCrv
    
def BowProfFillet(Input,StemCrv,KeelCrv):
    Crv1 = rs.coercecurve(StemCrv)
    Pt1 = rs.CurveEndPoint(StemCrv)
    Crv2 = rs.coercecurve(KeelCrv)
    Pt2 = rs.CurveStartPoint(KeelCrv)
    FilletCrvs = Curve.CreateFilletCurves(Crv1,Pt1,Crv2,Pt2,10.0,
        True,True,True,0.001, 0.01)
    doc.Objects.AddCurve(FilletCrvs[0])
    #StemCrv = rs.JoinCurves(Crvs[0],Crvs[1])
    #KeelCrv = Crvs[2]
    
    print "pause"
    return

"""
def SternLine():
    
    #return SternCrv

def DeckLine():
    
    #return DeckCrv
"""
def RunCommand( is_interactive ):
    #inputs
    Input = {'Beam' : 30,
                   'LOA'  : 100,
                   'LWL'  : 75,
                   'Depth' : 25,
                   'Origin_Height' : 7,
                   'Midbody_Hull_Length' : 20,
                   'Midbody_Hull_XPos' : -60,
                   'Midbody_Deck_Length' : 35,
                   'Midbody_Deck_XPos' : -67.5,
                   'Keel_Width' : 2,
                   'Bilge_Radius' : 3,
                   'Deadrise' : 1,
                   'Half_Entrance_Angle': 30,
                   'Bow_Rake_Angle' : 60,
                   'Bow_Radius' : 10,
                   'Prop_Clearance' : 6.5,
                   'Stern_Width' : 25,
                   'Stern_Length' : 4,
                   'Stern_Rise_Angle' : 7}
    
    StemCrv = StemLine(Input)
    KeelCrv = KeelLine(Input,StemCrv)
    BowProfFillet(Input,StemCrv,KeelCrv)

if( __name__=="__main__" ):
    RunCommand(True)

#4

Sorry, I should have added some explanation too. The code creates the stem line and keel line and then I attempt to fillet the intersection using Curve.CreateFilletCurves. I have no clue why the code isn’t working though. When the code fails I can manually fillet the curves just fine using the Rhino Fillet Command. I can even use the example code that shows how to use Curve.CreateFilletCurves http://developer.rhino3d.com/samples/rhinocommon/fillet-curves/, and create the fillet. My code tries to mimic the code in the link except for creating the curves instead of allowing the user pick the curves.

I need to use this function a bunch so any help on figuring this out would be appreciated.
Ian


#5

Hi,

This looks like it may be a bug in the filleting code… Your code looks OK. If you run with

FilletCrvs = Curve.CreateFilletCurves(Crv1,Pt1,Crv2,Pt2,10.0,
        False,False,False,0.001, 0.01)
#(instead of True,True,True)

you will see that the fillet will be created - but it is “going the wrong way”…

@pascal is aware of this thread and will look into it further…

–Mitch


(Pascal Golay) #6

Hi Ian - it seems to work, for now, if the points on the input curves are not the end points- so, here’s a hack (@Helvetosaur has a different one, also effective) that locates a point near the ends you want but not on the end:

def BowProfFillet(Input,StemCrv,KeelCrv):

Crv1 = rs.coercecurve(StemCrv)
dom =  Crv1.Domain
par = dom.Mid + ((dom.T1-dom.Mid)/2)
Pt1 = Crv1.PointAt(par)

Crv2 = rs.coercecurve(KeelCrv)
dom =  Crv2.Domain
par = dom.Mid + ((dom.T1-dom.Mid)/2)
Pt2 = Crv2.PointAt(par)

#Pt2 = rs.CurveStartPoint(KeelCrv)
FilletCrvs = Curve.CreateFilletCurves(Crv1,Pt1,Crv2,Pt2,10.0,
    True,True,True,0.001, 0.01)
    
if len(FilletCrvs) !=0: doc.Objects.AddCurve(FilletCrvs[0])
doc.Views.Redraw()
   
#StemCrv = rs.JoinCurves(Crvs[0],Crvs[1])
#KeelCrv = Crvs[2]

print "pause"
return

-Pascal


#7

That does the Trick! Thanks for your help!