Thursday, August 20, 2009

Cheng Hui Tower

Here is the tower example:



import py2rhino as p2r
print p2r._version

#===============================================================================
# Parameters
#===============================================================================
crv_centre = p2r.obj.NurbsCurve("e48e4900-47fa-44f4-b84a-4d7089520e09")
crv_radius = p2r.obj.NurbsCurve("0d528bea-63a5-4213-a669-2a0ba4cb2d9c")
floor_height = 4
facade_curve = 3
wall_panels = 9
#===============================================================================
# Main script
#===============================================================================
#get the start and end point of the centre curve
crv_s = crv_centre.prop.start_pnt()
crv_e = crv_centre.prop.end_pnt()

#sub divide the curves
points_centre = crv_centre.func.contour_pnts((0,0,crv_s[2]), (0,0,crv_e[2]), floor_height)
points_radius = crv_radius.func.contour_pnts((0,0,crv_s[2]), (0,0,crv_e[2]), floor_height)

#draw circles and save them in the list
circles = []
for point_counter in range(len(points_centre)):

#get the points out of the list
centre_pnt = points_centre[point_counter]
radius_pnt = points_radius[point_counter]

#create the circle
cir = p2r.obj.Circle.create((centre_pnt), radius_pnt[0])
circles.append(cir)

#draw a surface for each floor
surfaces = []
for cir_num in range(len(circles) - 1):

#get this circle and the next circle
cir1 = circles[cir_num]
cir2 = circles[cir_num + 1]

#create the average of the two centre points
cen_pnt1 = cir1.prop.center_pnt()
cen_pnt2 = cir2.prop.center_pnt()
cen_pnt_mid = ( (cen_pnt1[0] + cen_pnt2[0]) / 2.0, (cen_pnt1[1] + cen_pnt2[1]) / 2.0, (cen_pnt1[2] + cen_pnt2[2]) / 2.0 )

#get the average of the twp radii, and subtract the offset
rad_pnt1 = cir1.prop.radius()
rad_pnt2 = cir1.prop.radius()
rad_pnt_mid = ((rad_pnt1 + rad_pnt2) / 2.0) - facade_curve

#create the circle
cir_mid = p2r.obj.Circle.create((cen_pnt_mid), rad_pnt_mid)

#split the circles into points
points1 = list(cir1.func.divide_crv(wall_panels))
points2 = list(cir2.func.divide_crv(wall_panels))
points_mid = list(cir_mid.func.divide_crv(wall_panels))

#add one ore to the end
points1.append(points1[0])
points2.append(points2[0])
points_mid.append(points_mid[0])

for wall_panel_counter in range(wall_panels):

#create the first polyline
pt1 = points1[wall_panel_counter]
pt2 = points2[wall_panel_counter]
pt_mid = points_mid[wall_panel_counter]
pline1 = p2r.obj.Polyline.create((pt1, pt_mid, pt2))

#create the second polyline
pt1 = points1[wall_panel_counter + 1]
pt2 = points2[wall_panel_counter + 1]
pt_mid = points_mid[wall_panel_counter + 1]
pline2 = p2r.obj.Polyline.create((pt1, pt_mid, pt2 ))

#loft the two circles
srf = p2r.obj.NurbsSurface.create_by_loft((pline1, pline2))
surfaces.append(srf)

print "done"

No comments:

Post a Comment