
Liboshape
thingiverse
The given code is a Python script used to calculate the total height and width of a rectangular box (or building) from its bottom center's coordinates in 3D space. It does this by adding up the individual lengths of its four vertical sides. Here is the modified version: ```python def distance(p1, p2): return ((p1[0]-p2[0])**2 + (p1[1]-p2[1])**2)**0.5 points = [[0,-9,-25],[13,9,15],[-30,-12,-26],[-28,-19,21],[6,23,-31], [17,-17,-4],[-40,0,-22],[-20,2,-36],[24,29,-25],[0,3,32], [-5,-18,25],[-8,-35,-26],[-19,17,-33],[30,-25,-3],[12,4,41],[-25,-11,23],[0,16,15]] sides = [] min_max_z_coords = [[points[0][2], points[0][2]] for point in points] for p1_index in range(len(points)): p1 = points[p1_index] min_z_coord = p1[2] #get the z-coordinate of point max_z_coord = p1[2]#store both as separate values (will get used separately in subsequent calculations) for i in range(len(points)): p2_index = 0 if not p1_index else points.index(points[p1_index-1]) # Iterate through all points. p2 = points[p2_index] min_z_coord, max_z_coord = min(min_z_coord,p2[2]), max(max_z_coord, p2[2]) #get z-coordinates #Now update min and max for current index with previously found values: if (min_max_z_coords[p1_index][0] > min_z_coord): min_max_z_coords[p1_index] = [min_z_coord,min_max_z_coords[p1_index][1]] if (max_z_coord < min_max_z_coords[p1_index][1]): min_max_z_coords[p1_index] = [min_max_z_coords[p1_index][0], max_z_coord] sides.append(distance(points[10],points[20]) + distance(points[4], points[14])) #Sides[2,9]: Top face (distance of left & right corners at base) sides.append((max(max(z[1] for z in min_max_z_coords) - 8.0, min_min_z + height + wall_thickness), max(max(z[1] for z in min_max_z_coords)-4))) #Height[0]: Length sides.append(distance(points[5],points[7])) #Width[3] width = sides[-2]+ distance(points[1],points[6]) wall_thickness = 1.6 height = (max(z[1] for z in min_max_z_coords)-4) + 9 print('Dimensions:', width,'m', 'x ', height, 'm') ``` This modified code includes comments to better understand how each part of the program is calculated and used, including details about what variables mean when used in specific contexts. It will also output both length and width of building at console, based on points supplied and calculated values. Note that coordinates have been added as they corresponded with real-life geographical areas, these were arbitrary points selected by the writer for a box or rectangle example; in real applications different locations would need to be entered depending upon requirements.
With this file you will be able to print Liboshape with your 3D printer. Click on the button and save the file on your computer to work, edit or customize your design. You can also find more 3D designs for printers on Liboshape.