def Graph(S): A = S.pt Tr = S.Transforms() N = len(Tr) G = g.Pn(N + 1) T = I(4) G['pts'] = [A] for i in range(N): Ti = Tr[i] T = Mul(T, Ti) B = list(np.array(A) + np.array(MapPoint(T, [0, 0, 0]))) G['pts'].append(B) return G
def Cube(ww,hh,dd,mass=1e8): G1 = g.Cn(4) G2 = g.Pn(2) # graph G G = g.GraphProduct(G1,G2) # points to G pts = [[0,0,0],[0,0,dd],[ww,0,0],[ww,0,dd], [ww,hh,0],[ww,hh,dd],[0,hh,0],[0,hh,dd]] G['pts'] = pts # faces to G sorted by normals x,-x,y,-y,z,-z F = [[0,1,7,6],[4,5,3,2],[2,3,1,0], [6,7,5,4],[2,0,6,4],[1,3,5,7]] G['F'] = F G['N'] = map(lambda v: FaceNormal(G,v), range(len(F))) return G
red = [255, 0, 0] blue = [0, 0, 255] green = [0, 255, 0] i = 0 mouse = False print """ Left-Click mouse button to add points. Press 'e' to exit. Press 's' to select and 'd' to move mouse while select set. Press 'c' to clear screen. Press 'h' to load head. Press 'm' to load man. """ while True: gr.Clear() pyBezier(gr, pts, color=red) G = graph.Pn(len(pts)) G['pts'] = deepcopy(pts) #PlotGraph(gr,G,color=[240,255,240]) ## for pt in pts: ## gr.Point(pt,color=blue) if select and i_select is not None: C = pts[i_select] gr.Point(C, green) gr.Text("Select", 50, 50, color=red) ch = gr.Show("result", 15) if ch == ord('e'): break if ch == ord('a'): i = (i + 1) % len(pts) if ch == ord('s'): select = not select
def PathGraph(poly): G = graph.Pn(len(poly)) G['pts'] = poly return G