def plot_graph_turtle(G, wn="result", ms=-1, digraph=False): import graphics_turtle as racg gr = racg.Graphics() import plot_graph_simple_turtle as pgs w = h = gr.h G2 = g.CreateCircleGeometry(G, w, h, 0, h / 3) gr.Clear() pgs.Plot(gr, G2, digraph=digraph) pgs.Show(gr, wn, ms) gr.Close() return
def Wire0(r, ppath, m=10, n=40): assert (len(ppath) >= 2) C = [0, 0, 0] H1 = gra.Cn(m) H1 = gra.CreateCircleGeometry(H1, C[0], C[1], C[2], r) t = 0 dt = 1. / n path = [] while t <= 1: pt = B(t, ppath) path.append(pt) t = t + dt H = ext.Extrusion(H1, path, bcap=True, ecap=True, closed=True) return H
def Torus0(r1,r2,m=10,n=40): C = [0,0,0] H1 = gra.Cn(m) H1 = gra.CreateCircleGeometry(H1,C[0],C[1],C[2],r1) t = 0 dt = 2*pi/n path = [] while t <= 2*pi + dt: x = r2*sin(t) y = r2*cos(t) z = 0 pt = [x,y,z] path.append(pt) t = t + dt H = ext.Extrusion(H1,path,bcap=False,ecap=False,closed=True) return H
def Helix0(r, a, b, m=10, n=40, N=1): C = [0, 0, 0] H1 = gra.Cn(m) H1 = gra.CreateCircleGeometry(H1, C[0], C[1], C[2], r) t = 0 dt = 2 * pi / n path = [] while t <= 2 * pi * N + dt: # https://en.wikipedia.org/wiki/Helix x = a * sin(t) y = a * cos(t) z = b * t pt = [x, y, z] path.append(pt) t = t + dt H = ext.Extrusion(H1, path, bcap=True, ecap=True, closed=True) return H
pts = [] pt_move = [0,0] print("Select the two points on 2D plane") cv2.namedWindow("result") cv2.setMouseCallback("result",getxy) doc = {} doc["V"] = list(range(2)) doc["E"] = [[0,1]] doc["pts"] = [[119, 304],[480, 53]] doc = graph.Cn(4) w = 400 h = 400 cx,cy,cz = (w/2,h/2,0) r = 0.75*w/2 doc = graph.CreateCircleGeometry(doc,cx,cy,cz,r) doc['_id'] = 1 w = 600 h = 600 gr = racg.Graphics(w=w,h=h) def PlotGraph(gr,G,color): black = [0,0,0] for e in G['E']: A,B = [G['pts'][v] for v in e] gr.Line(A,B,color) for v in G['V']: A = G['pts'][v] gr.Point(A,black) return
def Circle(r, k): G = graph.Cn(k) C = [0, 0, 0] G = graph.CreateCircleGeometry(G, C[0], C[1], C[2], r) return G