Friday, April 27, 2012

Techo Tulips Along a Helix

The surface input is copied to the divisions on the helix, and the tulips with tail is created on each surface to achieve the above. 


import rhinoscriptsyntax as rs
import math as m 
import random as r


surf = rs.GetObject("surface",8)


# CREEPERS


a = 15
points = []


for i in range(0, 20):
    x = a*m.sin(m.pi/4*i)
    y = a*m.cos(m.pi/4*i)
    z = i * 2
    points.append([x,y,z])


distance = rs.Distance(points[0],points[1])


# DIVIDE THE SURFACE INTO GRID POINTS


d_u = rs.SurfaceDomain(surf,0)
d_v = rs.SurfaceDomain(surf,1)


d_u_len = (d_u[1] - d_u[0])/5
d_v_len = (d_v[1] - d_v[0])/5


# SCALED SURFACE


scale_surf = 2/((d_u[1] - d_u[0])/distance)
origin = rs.GetPointCoordinates("select a point on the surface")
surf = rs.ScaleObject(surf,origin[0],(scale_surf,scale_surf,scale_surf))


# MOVE SURFACE TO THE CURVE


surface = []


for i in range(0, len(points)):
    attractor_pt2 = points[i]
    translation = rs.VectorSubtract(points[i],origin[0])
    surface.append(rs.CopyObject(surf,translation))


# CALLING THE SURFACE TO POPULATE


for i in range(0,len(surface)):
    surf  = surface[i]
    d_u = rs.SurfaceDomain(surf,0)
    d_v = rs.SurfaceDomain(surf,1)
    
    d_u_len = (d_u[1] - d_u[0])/5
    d_v_len = (d_v[1] - d_v[0])/5
    
    cntrl_pts_surf = []
    listofnormals = []
    listofperp = []
    
    attractor_pt1 = points[i]
    attractor_pt2 = [0,0,0]
    
    for i in rs.frange(d_u[0],d_u[1],d_u_len):
        row_list = []
        normaltemplist = []
        perp_line = []
        vector_scale = 0.1
        for j in rs.frange(d_v[0],d_v[1],d_v_len):
            pt = rs.EvaluateSurface(surf,i,j)
            vector_scale = 1/(((rs.Distance(attractor_pt1, pt))/50) + vector_scale)
            normal_vector = rs.SurfaceNormal(surf,[i,j])
            normal_vector = rs.VectorUnitize(normal_vector)
            normal_vector = rs.VectorScale(normal_vector,vector_scale)
            normal_vector_pt = rs.VectorAdd(pt,normal_vector)
            normaltemplist.append(normal_vector_pt)
            row_list.append(pt)
            perp_line.append(rs.AddLine (normal_vector_pt, pt))
            row_list.append(pt)
        listofperp.append(perp_line)
        cntrl_pts_surf.append(row_list)
        listofnormals.append(normaltemplist)
    rs.DeleteObject(surf)
    curve = []


    arc_tot = []
    for i in range(0,len(cntrl_pts_surf)):
        arc = []
        for j in range(0, len(listofnormals[i])):
            line = rs.AddLine(attractor_pt2, listofnormals[i][j])
            mid_pt = rs.AddPoint(rs.CurveMidPoint(line))
            normal = rs.CurveNormal(line)
            rs.DeleteObject(line)
            normal = rs.VectorUnitize(normal)
            normal = rs.VectorScale(normal, 20)
            arc_mid_pt = rs.MoveObject(mid_pt,normal)
            arc.append(rs.AddCurve([listofnormals[i][j],cntrl_pts_surf[i][j],arc_mid_pt,attractor_pt2]))
            rs.DeleteObject(arc_mid_pt)
        arc_tot.append(arc)
    
    for i in range(0, len(arc_tot)):
        for m in range(0, len(arc_tot[i])):
            divisions = 20
            circle = []
            val = 1
            for j in range(divisions+1):
                parameter = j/divisions
                val = (val + j)
                radius = (rs.CurveLength(listofperp[i][m])/(2*val))*4
                eval_param = rs.CurveParameter(arc_tot[i][m],parameter)
                perp_frame = rs.CurvePerpFrame(arc_tot[i][m], eval_param)
                circle.append(rs.AddCircle(perp_frame, radius))
            rs.AddLoftSrf(circle)

No comments:

Post a Comment