#!/usr/bin/env python from __future__ import division import rhinoscriptsyntax as rs from math import * def sd(p1,p2): return [x1-x2 for x1,x2 in zip(p1,p2)] def sa(p1,p2): return [x1+x2 for x1,x2 in zip(p1,p2)] def sm(a,p): return [a*x for x in p] def smag(p): return sqrt(sum([x**2 for x in p])) def argmax(l): i=-1 m = l[i] for j in range(len(l)): if(l[j]>= l[i]): m = l[j] i=j return i if __name__ == '__main__': name = 'small-rhombicosidodecahedron' pr = rs.GetReal("Radius of polyhedron", 5, 0.) cr = rs.GetReal("Radius of edges", .1, 0.) extra = .25*cr # file = open('small-rhombicosidodecahedron.edges','r') file = open(name+'.edges','r') for line in file: e = map(float,line.strip('\n').split(',')) p1 = [pr*e[0],pr*e[1],pr*e[2]] p2 = [pr*e[3],pr*e[4],pr*e[5]] diff = sd(p2,p1) p1 = sd(p1, sm(extra/2,diff) ) plane = rs.PlaneFromNormal(p1, diff ) rs.AddCylinder (plane, (1+extra)*smag(diff), cr) file.close() # file = open(name+'.verts','r') # for line in file: # v = map(float,line.strip('\n').split(',')) # rs.AddSphere([pr*v[0],pr*v[1],pr*v[2]],smag(diff)/2) # cyls = rs.AllObjects() # for cyl1 in cyls: # for cyl2 in cyls: # new = rs.SplitBrep(cyl1, cyl2, delete_input=True) # if new: # big = argmax([rs.Area(n) for n in new]) # new.pop(big) # for n in new: # rs.DeleteObject(n)