def prot_to_xy(py): eb, ibs = py ebn = dpr.polygon_normal(eb) if ebn.near(dpv.nz()): prot = dpq.q_from_av(dpr.PI, dpv.x()) elif not ebn.near(dpv.z()): prot = dpq.q_from_uu(ebn, dpv.z()) else: prot = dpq.zero() return prot
def prot_to_xy(py): eb,ibs = py ebn = dpr.polygon_normal(eb) if ebn.near(dpv.nz()):prot = dpq.q_from_av(dpr.PI,dpv.x()) elif not ebn.near(dpv.z() ):prot = dpq.q_from_uu(ebn,dpv.z()) else: prot = dpq.zero() return prot
def windowframe(l, wlw, ww, wh, wz, lp): ps = windowhole(l, wlw, ww, wh, wz, lp) ps.extend([p.copy() for p in ps]) dpv.translate_coords(ps[:4], dpv.z().scale_u(-wlw / 2.0)) dpv.translate_coords(ps[4:], dpv.z().scale_u(wlw / 2.0)) p0, p1, p2, p3, p4, p5, p6, p7 = ps fpolys = ( ((p4.copy(), p0.copy(), p1.copy(), p5.copy()), ()), ((p5.copy(), p1.copy(), p2.copy(), p6.copy()), ()), ((p6.copy(), p2.copy(), p3.copy(), p7.copy()), ()), ((p7.copy(), p3.copy(), p0.copy(), p4.copy()), ()), ) return fpolys
def windowframe(l,wlw,ww,wh,wz,lp): ps = windowhole(l,wlw,ww,wh,wz,lp) ps.extend([p.copy() for p in ps]) dpv.translate_coords(ps[:4],dpv.z().scale_u(-wlw/2.0)) dpv.translate_coords(ps[4:],dpv.z().scale_u( wlw/2.0)) p0,p1,p2,p3,p4,p5,p6,p7 = ps fpolys = ( ((p4.copy(),p0.copy(),p1.copy(),p5.copy()),()), ((p5.copy(),p1.copy(),p2.copy(),p6.copy()),()), ((p6.copy(),p2.copy(),p3.copy(),p7.copy()),()), ((p7.copy(),p3.copy(),p0.copy(),p4.copy()),()), ) return fpolys
def wall(p1,p2,wh1,wh2,ww,doors = (),windows = ()): l = dpv.distance(p1,p2) a = dpr.angle_from_xaxis_xy(dpv.v1_v2(p1,p2)) ww2 = ww/2.0 bnd = [ dpv.vector( ww2, 0,0),dpv.vector(l-ww2, 0,0), dpv.vector(l-ww2,wh2,0),dpv.vector( ww2,wh1,0)] for d in doors: dhp = doorhole(l,*d) for x in range(len(dhp)-1,-1,-1): bnd.insert(1,dhp[x]) wholes = [tuple(windowhole(l,*w)) for w in windows] extras = [] for d in doors: dpolys = doorframe(l,*d) for dp in dpolys:extras.append(dp) for w in windows: wpolys = windowframe(l,*w) for wp in wpolys:extras.append(wp) x = dpv.z().scale_u(ww2) main0 = (tuple(bnd),tuple(wholes)) main1 = dpr.translate_polygon(dpr.copy_polygon(main0),x) dpr.translate_polygon(main0,x.flip()) wallgons = (main0,main1)+tuple(extras) #wallgons = (main1,)+tuple(extras) for wgon in wallgons: dpr.rotate_x_polygon(wgon,dpr.PI/2.0) dpr.rotate_z_polygon(wgon,a) dpr.translate_polygon(wgon,p1) return wallgons
def wall(p1, p2, wh1, wh2, ww, doors=(), windows=()): l = dpv.distance(p1, p2) a = dpr.angle_from_xaxis_xy(dpv.v1_v2(p1, p2)) ww2 = ww / 2.0 bnd = [ dpv.vector(ww2, 0, 0), dpv.vector(l - ww2, 0, 0), dpv.vector(l - ww2, wh2, 0), dpv.vector(ww2, wh1, 0) ] for d in doors: dhp = doorhole(l, *d) for x in range(len(dhp) - 1, -1, -1): bnd.insert(1, dhp[x]) wholes = [tuple(windowhole(l, *w)) for w in windows] extras = [] for d in doors: dpolys = doorframe(l, *d) for dp in dpolys: extras.append(dp) for w in windows: wpolys = windowframe(l, *w) for wp in wpolys: extras.append(wp) x = dpv.z().scale_u(ww2) main0 = (tuple(bnd), tuple(wholes)) main1 = dpr.translate_polygon(dpr.copy_polygon(main0), x) dpr.translate_polygon(main0, x.flip()) wallgons = (main0, main1) + tuple(extras) #wallgons = (main1,)+tuple(extras) for wgon in wallgons: dpr.rotate_x_polygon(wgon, dpr.PI / 2.0) dpr.rotate_z_polygon(wgon, a) dpr.translate_polygon(wgon, p1) return wallgons
def valid_pair(py1, py2): eb1, eb2 = py1[0], py2[0] for x in range(len(eb2)): one, two = eb2[x - 1], eb2[x] if one.near(two): print('invalid!!!') pdb.set_trace() ebn1 = dpr.polygon_normal(eb1) pj1 = dpv.project_coords(list(eb1), ebn1) pj2 = dpv.project_coords(list(eb2), ebn1) if not (dpr.isnear(pj2.x, pj2.y) and dpr.isnear(pj1.x, pj2.x)): return if ebn1.near(dpv.nz()): prot = dpq.q_from_av(dpr.PI, dpv.x()) elif not ebn1.near(dpv.z()): prot = dpq.q_from_uu(ebn1, dpv.z()) else: prot = dpq.zero() return prot
def valid_pair(py1,py2): eb1,eb2 = py1[0],py2[0] for x in range(len(eb2)): one,two = eb2[x-1],eb2[x] if one.near(two): print('invalid!!!') pdb.set_trace() ebn1 = dpr.polygon_normal(eb1) pj1 = dpv.project_coords(list(eb1),ebn1) pj2 = dpv.project_coords(list(eb2),ebn1) if not (dpr.isnear(pj2.x,pj2.y) and dpr.isnear(pj1.x,pj2.x)):return if ebn1.near(dpv.nz()):prot = dpq.q_from_av(dpr.PI,dpv.x()) elif not ebn1.near(dpv.z() ):prot = dpq.q_from_uu(ebn1,dpv.z()) else: prot = dpq.zero() return prot
def create_bbox(self,roomplan): x,y = roomplan[1]['x'],roomplan[1]['y'] l,w = roomplan[1]['l']-0.01,roomplan[1]['w']-0.01 cns = dpr.square(l,w,dpv.vector(x,y,0)) xpj = dpv.project_coords(cns,dpv.x()) ypj = dpv.project_coords(cns,dpv.y()) zpj = dpv.project_coords(cns,dpv.z()) bb = dbb.bbox(xpj,ypj,zpj) roomplan[1]['bbox'] = bb
def create_bbox(self, roomplan): x, y = roomplan[1]['x'], roomplan[1]['y'] l, w = roomplan[1]['l'] - 0.01, roomplan[1]['w'] - 0.01 cns = dpr.square(l, w, dpv.vector(x, y, 0)) xpj = dpv.project_coords(cns, dpv.x()) ypj = dpv.project_coords(cns, dpv.y()) zpj = dpv.project_coords(cns, dpv.z()) bb = dbb.bbox(xpj, ypj, zpj) roomplan[1]['bbox'] = bb
def wobblerot(self,p,d): polar = numpy.arcsin(d.cross(dpv.z()).magnitude()) azimuthal = dpv.angle_from_xaxis(d) if random.random() < 0.1:self.azimuthal_flip(p,d) elif random.random() < 0.5:self.azimuthal_up(p,d) else:self.azimuthal_down(p,d) if abs(polar) < numpy.pi/12.0:self.polar_down(p,d) elif polar < -numpy.pi/2.0:self.polar_down(p,d) elif polar > numpy.pi/2.0:self.polar_up(p,d)
def _project_uv_flat(self,rng = None): if rng is None:rng = range(len(self.faces)) for nf in rng: face = self.faces[nf] for fdx in face: p = self.pcoords[fdx] n = self.ncoords[fdx] if dpv.near(n,dpv.nx()) or dpv.near(n,dpv.x()): nu = p.copy().yz2d() elif dpv.near(n,dpv.ny()) or dpv.near(n,dpv.y()): nu = p.copy().xz2d() elif dpv.near(n,dpv.nz()) or dpv.near(n,dpv.z()): nu = p.copy().xy2d() else:continue self.ucoords[fdx] = nu
def model(self): p = dpv.zero() d = dpv.z() #ltree(-1)._realize(p,d) total = dmo.model() #tps = [(x,y) for x in range(3) for y in range(3)] tps = [(x, y) for x in range(1) for y in range(1)] for i, xy in enumerate(tps): x, y = xy kws = {'seed': i} self.ltree._realize(p, d) lmod = self.model lmod.translate(dpv.vector(10 * x, 10 * y, 0)) total._consume(lmod) return total
def model(self): p = dpv.zero() d = dpv.z() #ltree(-1)._realize(p,d) total = dmo.model() #tps = [(x,y) for x in range(3) for y in range(3)] tps = [(x,y) for x in range(1) for y in range(1)] for i,xy in enumerate(tps): x,y = xy kws = {'seed':i} self.ltree._realize(p,d) lmod = self.model lmod.translate(dpv.vector(10*x,10*y,0)) total._consume(lmod) return total
def generate(self,worn = 0): e1 = dpv.v1_v2(self.boundary[0],self.boundary[1]) e2 = dpv.v1_v2(self.boundary[1],self.boundary[2]) a = dpr.angle_from_xaxis_xy(e1) t = dpv.center_of_mass(list(self.boundary)) r = dpq.q_from_av(a,dpv.z()) tf,rf = t.copy().flip(),r.copy().flip() hl = e1.magnitude() hw = e2.magnitude() hbnd = [b.copy().translate(tf).rotate(rf) for b in self.boundary] house = dlh.house(hbnd,l = hl,w = hw) self.structures = [house] for s in self.structures: node = self._node_wrap(s.model(t,r)) self._nodes_to_graph(node) return self
def test(): import dilap.construct as dlc p = dpv.zero() d = dpv.z() #pythagoras_tree()._realize(p,d) #dragon_curve()._realize(p,d) total = dmo.model() #for l in range(5):tree(l)._realize(p,d) ltree(-1)._realize(p,d) tps = [(x,y) for x in range(3) for y in range(3)] for i,xy in enumerate(tps): x,y = xy kws = {'seed':i} lmod = ltree(-1,**kws)._realize(p,d).model lmod.translate(dpv.vector(10*x,10*y,0)) total._consume(lmod) dlc.build(total)
def polar_down(self,p,d): if d.near(dpv.z()) or d.near(dpv.nz()):qv = dpv.y() else:qv = d.cross(dpv.z()) d.rotate(dpq.q_from_av(-self.polar,qv))
def azimuthal_up(self,p,d):d.rotate(dpq.q_from_av(self.azimuthal,dpv.z())) def azimuthal_down(self,p,d):d.rotate(dpq.q_from_av(-self.azimuthal,dpv.z()))
def azimuthal_down(self,p,d):d.rotate(dpq.q_from_av(-self.azimuthal,dpv.z())) def azimuthal_flip(self,p,d):d.rotate(dpq.q_from_av(numpy.pi,dpv.z()))
def azimuthal_flip(self,p,d):d.rotate(dpq.q_from_av(numpy.pi,dpv.z())) def pitch_up(self,p,d):d.rotate(dpq.q_from_av(self.angle,dpv.x()))
def yaw_up(self,p,d):d.rotate(dpq.q_from_av(self.angle,dpv.z())) def yaw_down(self,p,d):d.rotate(dpq.q_from_av(self.angle,dpv.nz()))
def _transform(self,t,q,s): q = dpq.q_from_av(q,dpv.z()) dgc.context._transform(self,t,q,s) dpv.scale_coords(self.terrain_points,s) dpv.rotate_coords(self.terrain_points,q) dpv.translate_coords(self.terrain_points,t)