def star_tesselation(self): t = getattr(self,'_star_tesselation',None) if t is None: co_nt = NTracer(self.dimension) lines = [] planes = [Plane(co_nt,co_nt.Vector(islice(part.position,co_nt.dimension))) for part in self.parts] las = self.line_apothem_square() for pgroup in combinations(planes,co_nt.dimension-1): try: line = plane_line_intersection(co_nt,pgroup) except ValueError: pass else: if line: for lineb in lines: if almost_equal(line.p0,lineb.p0) and almost_equal(line.v,lineb.v): lineb.planes |= line.planes break else: outer_dist = line.dist_square(co_nt.Vector()) - las if outer_dist < 0.1: line.outer = outer_dist > -0.1 lines.append(line) pmap = {} for line in lines: pmap[line] = {} graph = FuzzyGraph() maxr = self.circumradius_square() + 0.1 for l1,l2 in combinations(lines,2): inter = line_intersection(co_nt,l1,l2) if inter and inter[0].square() < maxr: n = graph.add(inter[0],l1.planes | l2.planes,l1.outer or l2.outer) pmap[l1][n] = inter[1] pmap[l2][n] = inter[2] for line,poss in list(pmap.items()): if len(poss) == 0: continue if len(poss) == 1: graph.remove(poss[0]) continue poss = sorted(list(poss.items()),key=(lambda x: x[1])) if line.outer: for i in range(len(poss)-1): join(poss[i][0],poss[i+1][0]) elif len(poss) == 2: join(poss[0][0],poss[1][0]) elif len(poss) > 3: for i in range(2,len(poss)-2): graph.remove(poss[i][0]) join(poss[0][0],poss[1][0]) join(poss[-1][0],poss[-2][0]) t = [] self._star_tesselation = t for n in islice(graph.nodes,0,len(graph.nodes)-co_nt.dimension): for cycle in n.find_cycles(co_nt.dimension): t.append([nt.Vector(tuple(x.pos) + (0,) * (nt.dimension-co_nt.dimension)) for x in cycle] + [nt.Vector()]) n.detach() return t
def compose(part,order,schlafli): if schlafli.numerator * (math.pi - part.dihedral_s) >= math.pi * 2 * schlafli.denominator: exit("Component #{0} ({1}) is invalid because the angles of the parts add up to 360\u00b0 or\nmore and thus can't be folded inward".format(order,schlafli)) higher = PolyTope( order+1, schlafli, higher_dihedral_supplement(schlafli,part.dihedral_s), part.apothem) potentials = higher.add_face(Instance(part,nt.Vector.axis(order,higher.apothem))) while potentials: potentials = higher.propogate_faces(potentials) return higher jitter = nt.Vector((0,0,0) + (0.0001,) * (nt.dimension-3)) def process_movement(): global x_move, y_move, w_move if x_move or y_move or w_move: h = math.sqrt(x_move*x_move + y_move*y_move + w_move*w_move) a2 = camera.axes[0]*(x_move/h) + camera.axes[1]*(-y_move/h) if w_move: a2 += camera.axes[3] * (w_move / h) camera.transform(nt.Matrix.rotation( camera.axes[2], a2, h * ROT_SENSITIVITY)) camera.normalize() camera.origin = camera.axes[2] * cam_distance + jitter scene.set_camera(camera)