logo

[P]leat Diddy

Projects details

Generates a series of Structural “Pleats” based on Curves – Python Research V.1 [30.July.2011] 
“”” The input is a set of base curves, code uses vectors and vector math to set up the pleat depth then builds a mesh from them. This code does not generate the lines for you. In this particular example the lines were generated by Apo Mechanes Students [Garyfalia Arvaniti, loannis Karras, Dimitrios Ntavantzis]“””

[Python V1 – Pleat Generator from Crvs]

CODE

import rhinoscriptsyntax as rs
from System.Drawing import Color 
"""Script Written By Luis Quinones
Script Copywritten by [n]igma + computationalMatter
www.luisquinonesdesign.com
www.computationalmatter.com
www.cargocollective.com/studioboom
Script Version Wednesday, July 30, 2011"""

import rhinoscriptsyntax as rs
from System.Drawing import Color

arrCrvs = rs.GetObjects("Crvs",rs.filter.curve)
distanceThresh = rs.GetReal("DistanceTONotMakeMesh",30)
dblVecScale = rs.GetReal("PLEAT_SCALE",1,-1,5)

#rs.EnableRedraw(False)
faceVert = [[0,1,2,3]]
crvPtCount = rs.CurvePointCount(arrCrvs[0])
for z in range(len(arrCrvs)):    
    build = rs.RebuildCurve(arrCrvs[z],2,100)
    ptcount = rs.CurvePointCount(arrCrvs[z])    
    print ptcount
for i in range(len(arrCrvs)-1):    
    if i == len(arrCrvs):        
        print "LAST"       
        crvPts2 = rs.CurvePoints(len(arrCrvs))        
    else:        
        crvPts = rs.CurvePoints(arrCrvs[i])
        crvPts2 = rs.CurvePoints(arrCrvs[i+1])
        
    for j in range(crvPtCount-1):
        #meshVert = crvPts[j],crvPts[j+1],crvPts2[j+1],crvPts2[j]      
        param = rs.CurveClosestPoint(arrCrvs[i],crvPts[j])
        arrData = rs.CurveCurvature(arrCrvs[i],param)       
        param2 = rs.CurveClosestPoint(arrCrvs[i],crvPts[j+1])
        arrData2 = rs.CurveCurvature(arrCrvs[i],param2)        
        param3 = rs.CurveClosestPoint(arrCrvs[i+1],crvPts2[j])
        arrData3 = rs.CurveCurvature(arrCrvs[i+1],param3)        
        param4 = rs.CurveClosestPoint(arrCrvs[i+1],crvPts2[j+1])
        arrData4 = rs.CurveCurvature(arrCrvs[i+1],param4)        
        if arrData :           
            arrTangent = arrData[1]               
            arrTangent2 = arrData2[1]                            
            arrTangent3 = arrData3[1]                       
            arrTangent4 = arrData4[1]                        
            arrEnd = crvPts[j][0] + arrTangent[0],crvPts[j][1] + arrTangent[1], crvPts[j][2] + arrTangent[2]
            testpoint2 = rs.AddPoint(arrEnd)
            rs.ObjectColor(testpoint2,Color.Purple)            
            arrEnd2 = crvPts[j+1][0] + arrTangent2[0],crvPts[j+1][1] + arrTangent2[1], crvPts[j+1][2] + arrTangent2[2]
            testpoint3 = rs.AddPoint(arrEnd2)
            rs.ObjectColor(testpoint3,Color.Pink)            
            arrEnd3 = crvPts2[j][0] + arrTangent3[0],crvPts2[j][1] + arrTangent3[1], crvPts2[j][2] + arrTangent3[2]           
            arrEnd4 = crvPts2[j+1][0] + arrTangent4[0],crvPts2[j+1][1] + arrTangent4[1], crvPts2[j+1][2] + arrTangent4[2]                
        InitVec = rs.VectorCreate(crvPts2[j],crvPts[j])
        checkDis = rs.Distance(crvPts2[j],crvPts[j])      
        InitVec2 = rs.VectorCreate(crvPts2[j+1],crvPts[j+1])
        checkDis2 = rs.Distance(crvPts2[j+1],crvPts[j+1])        
        scale = checkDis * 0.8
        scale2 = checkDis * 0.2        
        scale3 = checkDis2 * 0.8
        scale4 = checkDis2 * 0.2
        
        vecUnit = rs.VectorUnitize(InitVec)
        vec2 = rs.VectorScale(vecUnit,scale)
        vecMain = rs.VectorAdd(vec2,crvPts[j])
        ptB = rs.AddPoint(vecMain)
        
        vecSD2 = rs.VectorScale(vecUnit,scale2)
        vecSD3 = rs.VectorAdd(vecSD2,crvPts[j])
        ptA = rs.AddPoint(vecSD3)
                
        vecUnit2 = rs.VectorUnitize(InitVec2)
        vec22 = rs.VectorScale(vecUnit2,scale3)
        vecMain2 = rs.VectorAdd(vec22,crvPts[j+1])
        ptB2 = rs.AddPoint(vecMain2)
        
        vecSD22 = rs.VectorScale(vecUnit2,scale4)
        vecSD32 = rs.VectorAdd(vecSD22,crvPts[j+1])
        ptA2 = rs.AddPoint(vecSD32)
                     
        tempVec = rs.VectorCreate(arrEnd,crvPts[j])
        tempVec2 = rs.VectorCreate(vecSD3,crvPts[j])
        
        tempVec3 = rs.VectorCreate(arrEnd2,crvPts[j+1])
        tempVec4 = rs.VectorCreate(vecSD32,crvPts[j+1])
        
        tempVec5 = rs.VectorCreate(arrEnd3,crvPts2[j])
        tempVec6 = rs.VectorCreate(vecMain,crvPts2[j])
        
        tempVec7 = rs.VectorCreate(arrEnd4,crvPts2[j+1])
        tempVec8 = rs.VectorCreate(vecMain2,crvPts2[j+1])
                
        perpVec = rs.VectorCrossProduct(tempVec,tempVec2)
        perpVec = rs.VectorReverse(perpVec)
        perpVec = rs.VectorUnitize(perpVec)
        perpVec = rs.VectorScale(perpVec,dblVecScale)
        zPt = rs.PointAdd(crvPts[j],perpVec)
        
        perpVec2 = rs.VectorCrossProduct(tempVec3,tempVec4)
        perpVec2 = rs.VectorReverse(perpVec2)
        perpVec2 = rs.VectorUnitize(perpVec2)
        perpVec2 = rs.VectorScale(perpVec2,dblVecScale)
        zPt2 = rs.PointAdd(crvPts[j+1],perpVec2)
        #testPt = rs.AddPoint(zPt)
        #rs.ObjectColor(testPt,Color.Red)
        
        perpVec3 = rs.VectorCrossProduct(tempVec5,tempVec6)
        perpVec3 = rs.VectorUnitize(perpVec3)
        perpVec3 = rs.VectorScale(perpVec3,dblVecScale)
        zPt3 = rs.PointAdd(crvPts2[j],perpVec3)              
        perpVec4 = rs.VectorCrossProduct(tempVec7,tempVec8)
        perpVec4 = rs.VectorUnitize(perpVec4)
        perpVec4 = rs.VectorScale(perpVec4,dblVecScale)
        zPt4 = rs.PointAdd(crvPts2[j+1],perpVec4)                
        meshVert = zPt,vecSD3,vecSD32,zPt2       
        meshVert2 = vecSD3,vecMain,vecMain2,vecSD32        
        meshVert3 = zPt3,vecMain,vecMain2,zPt4                
        distance = rs.Distance(crvPts[j],crvPts2[j+1])        
        if distance < distanceThresh:        
            outmesh = rs.AddMesh(meshVert,faceVert)
            outmesh2 = rs.AddMesh(meshVert2,faceVert)
            outmesh3 = rs.AddMesh(meshVert3,faceVert)
            #rs.ObjectLayer(outmesh,layer)
Update
  • Share

Leave a reply

Your email address will not be published. Required fields are marked *