def profile_triangulation(): import dilap.mesh.piecewisecomplex as pwc ps1 = tuple(dpr.point_ring(100,32)) ps2 = tuple(dpr.point_ring(20,8)) ps3 = tuple(dpr.point_ring(100,64)) ps4 = tuple([p.copy() for p in ps2]) q = dpq.q_from_av(numpy.pi/2.0,dpv.xhat) for p in ps1:p.rotate(q) for p in ps2:p.rotate(q) dpv.translate_coords(list(ps1),dpv.vector(0,100,0)) dpv.translate_coords(list(ps2),dpv.vector(0,100,0)) dpv.translate_coords(list(ps3),dpv.vector(0,0,-100)) dpv.translate_coords(list(ps4),dpv.vector(0,0,-100)) polygons = ((ps1,(ps2,)),(ps3,())) #polygons = ((ps3,(ps4,)),) #polygons = ((ps3,()),) plc = pwc.piecewise_linear_complex() plc.add_polygons(*polygons) dprf.profile_function(plc.triangulate) #dprf.profile_function(plc.triangulate_xy) ax = plc.plot() plt.show()
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 orient_loop(loop,targetnormal,control = None): if control is None:control = dpv.center_of_mass(loop) n = normal(*loop[:3]) if n == targetnormal.copy().flip(): #print('HACK?') #qrot = dpq.q_from_av(numpy.pi,dpv.zhat) qrot = dpq.q_from_av(PI,dpv.yhat) else:qrot = dpq.q_from_uu(n,targetnormal) looprot = dpq.rotate_coords(loop,control,qrot) return looprot
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 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 grow(self,seed,pfaces,nfaces,years): gface,seedposition = seed gpt = seedposition.copy() pactive = pfaces[gface] tactive = dpr.tangent(*pactive) nactive = dpr.normal(*pactive) ctrlpts = [gpt.copy()] ctrlpts.append(ctrlpts[-1].copy().translate_z(0.25)) pi2 = numpy.pi/2.0 while years: years -= 1 r = 1.0 t = -pi2/3.0 if years % 2 == 0 else pi2/3.0 q = dq.q_from_av(t,nactive) #dgpt is where to go from the last point # it must be aware of structures to creep on dgpt = tactive.copy().rotate(q).scale_u(r) ctrlpts.append(ctrlpts[-1].copy().translate(dgpt)) tactive = dpv.v1_v2(ctrlpts[-2],ctrlpts[-1]).normalize() # consider if the active face should change ctrlpts.append(ctrlpts[-1].copy().translate_z(-0.25)) #splined = [] #splined.append(ctrlpts[0]) #for x in range(3,len(ctrlpts)): # v1,v2,v3,v4 = ctrlpts[x-3],ctrlpts[x-2],ctrlpts[x-1],ctrlpts[x] # splined.extend(dpv.vector_spline(v1,v2,v3,v4,5)) ##splined.append(ctrlpts[-1]) #splined = ctrlpts[:] loop = dpr.point_ring(0.1,8) ctrl = dpv.zero() loop.append(loop[0].copy()) nfs = self._extrude(loop,ctrlpts,dpv.zero()) return self
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)
def roll_down(self,p,d):d.rotate(dpq.q_from_av(self.angle,dpv.ny())) def randdirrot(self,p,d):
def roll_up(self,p,d):d.rotate(dpq.q_from_av(self.angle,dpv.y())) def roll_down(self,p,d):d.rotate(dpq.q_from_av(self.angle,dpv.ny()))
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 pitch_up(self,p,d):d.rotate(dpq.q_from_av(self.angle,dpv.x())) def pitch_down(self,p,d):d.rotate(dpq.q_from_av(self.angle,dpv.nx()))
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 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_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 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))