Forgot password?

Create an account!

Forum

« back

RhinoScript – curve to surface

Messages

Please log in to write a message.

  • 1. eileenee (Oct 07, 2009 09.33):

    hello. everyone
    I got a rhinoscript from 5osa.tistory.com/category/5osa%60life
    but there is some problem.
    I want these curves make symmetry srufaces.
    how can i make it?
    help me please

    Option Explicit
    'Script written by Noclew
    'Script copyrighted by
    'Script version 0.2
    'ReDim b1 : b1 = 2
    Private a1,b1,c1,d1,e1,f1
    Call Main()
    Sub Main()        
     
        Dim arrCrvs : arrCrvs = rhino.getobjects("select curves",4,,True)
        If isNull(arrCrvs) Then Exit Sub
       
        If IsEmpty(a1) Then    
            a1 = 12
        End If
        'If IsEmpty(b1) Then    
        b1 = rhino.distance(rhino.EvaluateCurve(arrCrvs(0),0.5),rhino.EvaluateCurve(arrCrvs(1),0.5))
        'End If
        If IsEmpty(c1) Then    
            c1 = 90
        End If
        If IsEmpty(d1) Then    
            d1 = 3
        End If
        If IsEmpty(e1)Then    
            e1 = 0
        End If
        If IsEmpty(f1)Then    
            f1 = 0
        End If
       
       
        Dim arrItems, arrValue, pB
       
        arrItems = array(_
            "number of sample",_
            "width",_
            "angle",_
            "radius(0: even 1: dec 2: -dec 3: syn)",_
            "rotate type(0: both end, 1: one end, 2: reveres of 1)",_
            "gap (0:default -2 :wide)")
       

        Dim arrValues
       
        arrValues = array(a1,b1,c1,d1,e1,f1)
        pB = rhino.propertylistbox(arrItems,arrValues,"option","KNL skin script")
       
        'converting values to double
        For i = 0 To ubound(arrValues)
            If pB(i)="" Then
                Call rhino.messagebox("parameter is missing!!!")
                Exit Sub
            End If
            pB(i) = cdbl(pB(i))
        Next
       
        a1 = pB(0) 'Sample count
        b1 = pB(1) 'width
        c1 = pB(2) 'Max angle
        d1 = pB(3) 'twisting type
        e1 = pB(4) 'end point type
        f1 = pb(5) 'expention constant
       
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
       
        Call rhino.EnableRedraw(False)    
       
        Dim angleVar, vecCrvNormal
        Dim i
       
        'reparameterizing all line
        i = 0
        For i = 0 To ubound(arrCrvs)
            reparameterize(arrCrvs(i))
        Next
       
        'line making looping start
        For i = 0 To ubound(arrCrvs)
           
            'get tangent vector
            If i = ubound(arrCrvs) Then
            Else
                vecCrvNormal = rhino.VectorCreate(rhino.EvaluateCurve(arrCrvs(i),0.5),rhino.EvaluateCurve(arrCrvs(i+1),0.5))
            End If
           
           
            angleVar = angleCalc (pB(3), pB(2), ubound(arrCrvs), i)
            Call cosRotation (angleVar , arrCrvs(i), pB(1) , pB(0), vecCrvNormal, pB(4))
         
        Next
       
        Call rhino.EnableRedraw(True)
       
    End Sub

    Function angleCalc ( ByRef n, ByVal dblAngle , ByRef count, ByRef CurrentNumber )
       
       
        If n = 0 Then    
            angleCalc = dblAngle
        ElseIf n = 1 Then
            angleCalc = dblAngle * sin(0.5 * rhino.Pi + (0.5*rhino.pi)*(currentNumber/count))
        ElseIf n = 2 Then
            angleCalc = dblAngle * sin((0.5*rhino.pi)*(currentNumber/count))
        Else
            'angleCalc = dblAngle * sin( (rhino.pi) * (currentNumber/count) * StretchDomain((currentNumber/count)) )
            angleCalc = dblAngle * sin((rhino.pi) * (currentNumber/count) )
        End If
       
    End Function

    Function cosRotation (ByRef dblAngle, ByRef strCrv, ByRef dblWidth, ByRef intSample, ByRef vecCrvNormal, ByRef RotateType)
       
        cosRotation = Null
       
        Dim dblCosRange : dblCosRange = dblAngle/90
        Dim ptOnCrv()
        Dim dblRotateAngle
        Dim strLoftline(1)
        Dim temp, temp2
        Dim ptA(),ptB()
        Dim expConst
        Dim t,i : i = -1
        For t = 0 To 1 Step 1/intSample
            i = i + 1
            ReDim Preserve ptOnCrv(i) : ptOnCrv(i) = rhino.EvaluateCurve(strCrv,t)
           
            expConst = StretchDomain(t,f1)
           
            If RotateType = 0 Then
                temp = - 1 * ( 0.5 - ( cos(2*rhino.pi*t * expConst) * 0.5 ))
            ElseIf rotatetype = 1 Then
                'temp = - 1 * ( 0.5 - ( cos(1*rhino.pi*t * expConst2) * 0.5 ))
                temp = -cos(rhino.pi*1.5 + rhino.Pi*0.5*t)
            Else
                temp = -cos(0.5*rhino.pi*t)
            End If
           
            dblRotateAngle = dblAngle * temp
           
            temp2 = dblWidth
                       
            temp = vecrotate( strCrv, ptonCrv(i),t,temp2,dblRotateAngle,vecCrvNormal )
           
            ReDim Preserve ptA(i),ptb(i)
            ptA(i) = temp(0)
            ptB(i) = temp(1)
           
        Next

       
        strLoftline(0) = rhino.AddInterpCurve(ptA)
        strLoftline(1) = strcrv
       
        cosRotation = rhino.AddLoftSrf(strLoftline)
       
        Call rhino.DeleteObject(strLoftline(0))    

       
       
    End Function

    Function vecRotate ( ByRef strCrv, ByRef ptOnCrv, ByRef t, ByRef dblWidth, ByRef dblRotateAngle,ByRef vecCrvNormal)
        vecRotate = Null
        Dim crvCurvature, CrvTan, crvPerp, CrvNormal
        crvCurvature = CurveCurvature(strCrv,t)
               
        If isnull(crvCurvature) Then
            CrvTan = rhino.CurveTangent(strCrv,t)
            crvPerp = rhino.VectorUnitize(vecCrvNormal)
            crvNormal = rhino.VectorUnitize(vecCrvNormal)
        Else        
            CrvTan = rhino.CurveTangent(strCrv,t)
            crvPerp = rhino.VectorUnitize(vecCrvNormal)
            crvNormal = rhino.VectorUnitize(vecCrvNormal)
        End If
       
        'dim temp : temp = 1
        'Dim temp : temp = (cos( (2 * rhino.pi) * t )+1 ) / 2
        Dim temp
        If t < 0.7 Then
            temp = 1 - sin(0.5 * rhino.Pi * (t / 0.7))
        Else
            temp = 0
        End If
       
           
       
        Dim vecRotated : vecRotated = rhino.VectorScale(crvNormal,( (2 * dblWidth /3)*temp + (1*dblWidth)/3) )
        vecRotated = rhino.VectorRotate(vecRotated,dblRotateAngle,crvTan)
       
        Dim pt1 : pt1 = rhino.PointAdd(ptOnCrv,vecRotated)
        Dim pt2 : pt2 = rhino.PointAdd(ptOnCrv,rhino.VectorReverse(vecrotated))

        vecRotate = array(pt1,pt2)    
    End Function

    Function StretchDomain(i,f1)
        stretchDomain = i
        Dim yY
        yY = f1 * (i - 0.5) + 1
        StretchDomain = yY
    End Function



    Function reparameterize(strObjectID)
        If Rhino.IsCurve(strObjectID) = True Then
            Call rhino.SelectObject(strObjectID)
            Call rhino.Command("reparameterize 0 1")
            Call rhino.UnselectAllObjects()
        End If
        If Rhino.IsSurface(strObjectID) = True Then
            Call rhino.SelectObject(strObjectID)
            Call rhino.Command("reparameterize 0 1 0 1")
            Call rhino.UnselectAllObjects()
        End If        
    End Function
    curve to surface
Recommend

Why are these buttons gray?