### DM2 ### hu_03 ### von Aleksandar Dudurovic/kairos28 ### 12231403 ### Gruppe Gruber 03 import rhinoscriptsyntax as rs import random, time, sys ### sys.path.append("P:/kairos28/DM2") import DM_lib as dm ### reload(dm) ############################## rs.UnitSystem(3) rs.ShowGrid(view=None, show=0) rs.ShowGridAxes(view=None, show=0) rs.ViewDisplayMode(view=None, mode="Wireframe") rs.EnableRedraw(0) dm.PointRadius(displayModeX=0, rad=3, styl=1) rs.DeleteObjects(rs.AllObjects()) ###################################### anz = random.choice( range(2**4, 2**8, 4) ) dm.allCoords = dm.setUp_hu_03( anz ) coordsCir = dm.allCoords[0] ### calling def from DM_lib to get *new* set of coords coordsCub = dm.allCoords[1] ### calling def from DM_lib to get *new* set of coords ###################################### randomVec = [random.uniform(-30,30) for i in range(3)] coordsCub = [rs.VectorRotate(cor, randomVec[0], randomVec) for cor in coordsCub] coordsCir = [rs.VectorRotate(cor, randomVec[0], randomVec) for cor in coordsCir] siz = rs.Distance( coordsCub[0], coordsCub[1] ) ### edge length of cubus #dm.textDots( coordsCub ) #rs.AddCurve( coordsCub, 1 ) #rs.AddCurve( coordsCir, 1 ) #dm.textDots( coordsCir ) anz = len(coordsCub) print "*** anz =", anz print "*** siz =", round(siz, 2), "/ edge lenght =", round(siz, 2),"*",int(anz/4),"=", round(siz*anz/4, 2) print "*** **********\n" #for i in range(1, 32): # p0 = coordsCub[i] # p1 = coordsCir[i] # rs.AddCurve( [ p0, p1 ] ) ### here we go: def create_structure(coords, size, divisions): # direction vectors vecX = rs.VectorSubtract(coords[1], coords[0]) vecY = rs.VectorSubtract(coords[2], coords[0]) vecZ = rs.VectorCrossProduct(vecX, vecY) vecZ = rs.VectorUnitize(vecZ) # Z vector vecZ = rs.VectorScale(vecZ, size) # base and top points ptA = coords[0] ptB = rs.VectorAdd(ptA, rs.VectorScale(vecX, divisions / 4)) ptC = rs.VectorAdd(ptB, rs.VectorScale(vecY, divisions / 4)) ptD = rs.VectorAdd(ptA, rs.VectorScale(vecY, divisions / 4)) ptE = rs.VectorAdd(ptA, vecZ) ptF = rs.VectorAdd(ptB, vecZ) ptG = rs.VectorAdd(ptC, vecZ) ptH = rs.VectorAdd(ptD, vecZ) # curves for the base and top base_curve = rs.AddCurve([ptA, ptB, ptC, ptD, ptA], 1) top_curve = rs.AddCurve([ptE, ptF, ptG, ptH, ptE], 1) # text dots at key points for i, pt in enumerate([ptA, ptB, ptC, ptD, ptE, ptF, ptG, ptH]): rs.AddTextDot(chr(65 + i), pt) # Labels A, B, C, D, E, F, G, H # random points around the center center = rs.PointDivide(ptA + ptG, 2) for _ in range(50): rand_vector = [random.uniform(-1, 1) for _ in range(3)] random_point = rs.VectorAdd(center, rs.VectorScale(rs.VectorUnitize(rand_vector), random.uniform(1, size))) rs.AddPoint(random_point) # sphere sphere_radius = size / 4 num_points = 100 for i in range(num_points): # Y-coordinate y = sphere_radius * (1 - (2 * i / float(num_points - 1))) radius = (sphere_radius ** 2 - y ** 2) ** 0.5 # radius at height y # Randomizing X and Z to form points around the sphere for j in range(10): x = radius * random.uniform(-1, 1) z = radius * random.uniform(-1, 1) # Ensuring x and z are within the circle of the current radius if x ** 2 + z ** 2 <= radius ** 2: sphere_point = rs.AddPoint(rs.VectorAdd(center, (x, y, z))) # Example coordinates and parameters coordsCub = [rs.coerce3dpoint((0, 0, 0)), rs.coerce3dpoint((10, 0, 0)), rs.coerce3dpoint((0, 10, 0))] size = 10 divisions = 4 # Running the structure creation create_structure(coordsCub, size, divisions)