def BodyGraph(G, Gs, Gseg, t, q, s): H = {} H['V'] = [] H['E'] = [] H['F'] = [] H['N'] = [] H['pts'] = [] degrees = 90 axis = [0, 1, 0] q0 = aff.HH.rotation_quaternion(degrees, axis[0], axis[1], axis[2]) A = Gseg['pts'][0] Hf = ext.CubeObj(300, 5, 300, A, q0, s) H = ext.GraphUnionS(H, Hf) for e in Gseg['E']: u, v = e A, B = [Gseg['pts'][w] for w in e] v1 = np.array(B) - np.array(A) v1n = np.linalg.norm(v1) epsilon = 1e-5 if abs(v1n) < epsilon: continue v1 = v1 / np.linalg.norm(v1) axis1 = [1, 0, 0] axis2 = list(v1) q1 = ext.AimAxis(axis1, axis2) q1 = q1 * q0 r = 10 h = d(A, B) t0 = list(np.array(A) + h / 2. * v1) s0 = [1, 1, 1] He = bs.Cylinder(r, h, t0, q1, s0, n=10, m=10) H = ext.GraphUnionS(H, He) Hf = bs.Sphere(40, A, q1, s0, n=10, m=10) H = ext.GraphUnionS(H, Hf) #Hf = bs.Cone(60,150,B,q1,s0,n=10,m=10) #H = ext.GraphUnionS(H,Hf) degrees = 0 # 180 axis = [0, 0, 1] q2 = aff.HH.rotation_quaternion(degrees, axis[0], axis[1], axis[2]) q = q * q2 pts = H['pts'] C = Gseg['pts'][0] pts = aff.Translate(pts, -C[0], -C[1], -C[2]) pts = aff.Rotate(pts, q) pts = aff.Scale(pts, s[0], s[1], s[2]) pts = aff.Translate(pts, t[0], t[1], t[2]) H['pts'] = pts return H
def SquareTable1(): G = {} G['V'] = [] G['E'] = [] G['F'] = [] G['N'] = [] G['pts'] = [] w, h, d = [500, 500, 20] degrees = 0 axis = [0, 1, 0] q = aff.HH.rotation_quaternion(degrees, axis[0], axis[1], axis[2]) scale = 1. s = [scale, scale, scale] # the same scale as previous for caps t = [-w / 2., -h / 2., -d / 2.] H1 = ext.CubeObj(w, h, d, t, q, s) G = ext.GraphUnionS(G, H1) def Leg(t, q, s): height = w * (3. / 5.) r1 = 8. r2 = 12. H = TableLeg(height, r1, r2, n=10, m=10) pts = H['pts'] C = aff.Center(pts) pts = aff.Translate(pts, -C[0], -C[1], -C[2], align=False) pts = aff.Rotate(pts, q, align=False) pts = aff.Scale(pts, s[0], s[1], s[2], align=False) pts = aff.Translate(pts, t[0], t[1], t[2], align=False) H['pts'] = pts return H N1 = 2 N2 = 2 for j in range(N2): for i in range(N1): height = w * (3. / 5.) t = [ 2 * w * (1. * i / N1) - w / 2, 2 * h * (1. * j / N2) - h / 2, -height * .4 ] degrees = 0 axis = [0, 1, 0] q = aff.HH.rotation_quaternion(degrees, axis[0], axis[1], axis[2]) scale = 1. s = [scale, scale, scale] # the same scale as previous for caps Hij = Leg(t, q, s) G = ext.GraphUnionS(G, Hij) return G
def CoffeeCup(): G = {} G['V'] = [] G['E'] = [] G['F'] = [] G['N'] = [] G['pts'] = [] scale = 10. w,h,d = [3.25*scale,3.25*scale,3.8*scale] degrees = 0 axis = [0,1,0] q = aff.HH.rotation_quaternion(degrees,axis[0],axis[1],axis[2]) scale = 1. s = [scale,scale,scale] # the same scale as previous for caps t = [-w/2.,-h/2.,-d/2.] H1 = ext.CubeObj(w,h,d, t,q,s) G = ext.GraphUnionS(G,H1) return G
def CoffeeCup0(n=30,m=20,r0=20.): flag_cup = True flag_handle = True H1 = {} H1['V'] = [] H1['E'] = [] H1['pts'] = [] H1['F'] = [] H1['N'] = [] H2 = {} H2['V'] = [] H2['E'] = [] H2['pts'] = [] H2['F'] = [] H2['N'] = [] if flag_cup: # polygon curve of surface of revolution # Create Cup. At present, its imperfect recreating # a cover to coffee cup. curve1a = [[406, 388], [441, 384], [469, 378], [489, 363], [506, 347], [518, 330], [520, 314], [522, 297], [525, 276], [528, 258], [530, 228], [528, 182], [528, 150], [527, 113], [527, 91], [532, 73], [540, 68]] curve1b = [[554, 70], [554, 86], [549, 108], [550, 136], [546, 181], [547, 214], [544, 249], [544, 268], [538, 281], [540, 288], [539, 300], [531, 312], [532, 329], [526, 350], [513, 362], [502, 378], [482, 393], [446, 406], [417, 409]] curve1 = curve1a + curve1b x0 = curve1[0][0] x_min = min(map(lambda pt: pt[0]-x0,curve1)) x_max = max(map(lambda pt: pt[0]-x0,curve1)) y_min = min(map(lambda pt: pt[1],curve1)) y_max = max(map(lambda pt: pt[1],curve1)) degrees = 0 axis = [0,1,0] q = aff.HH.rotation_quaternion(degrees,axis[0],axis[1],axis[2]) scale = 1. s = [scale,scale,scale] # the same scale as previous for caps t = [0,0,0] H1 = rc.RevolveCurve(curve1,t,q,s, n, bcap=False, ecap=False) if flag_handle: # Create Handle curve2 = [[203, 130], [189, 114], [165, 102], [149, 100], [132, 101], [116, 106], [106, 113], [107, 128], [112, 152], [118, 169], [127, 184], [138, 201], [149, 208], [165, 209], [186, 214], [207, 213]] # Assume curve has symmetry y-axis x0 = curve2[0][0] x_min = min(map(lambda pt: pt[0]-x0,curve2)) x_max = max(map(lambda pt: pt[0]-x0,curve2)) y_min = min(map(lambda pt: pt[1],curve2)) y_max = max(map(lambda pt: pt[1],curve2)) poly_wb = deepcopy(curve2) pts = map(lambda pt: [0,pt[1],0], poly_wb) y_min = min(map(lambda pt: pt[1],poly_wb)) y_max = max(map(lambda pt: pt[1],poly_wb)) doc = g.Cn(m) cx,cy,cz = [0,0,0] doc1 = rc.CreateCircleGeometry(doc,cx,cy,cz,r0) spath = [] path = [] pti = poly_wb[0] xi,yi = pti yi_last = yi dx = x_max-x_min dy = y_max-y_min for i in range(len(poly_wb)): pti = poly_wb[i] xi,yi = pti r = abs(xi - x0) dy = yi-yi_last epsilon = .1 if abs(dy) > epsilon: spath.append(1.) path.append([xi,yi,0]) degrees = 90+180 axis = [1,0,0] q0 = aff.HH.rotation_quaternion(degrees,axis[0],axis[1],axis[2]) q = q0 t = [-184,0,100] s = [1,1,1] C = aff.Center(path) pts = aff.Translate(path,-C[0],-C[1],-C[2],align=False) pts = aff.Rotate(pts,q,align=False) pts = aff.Scale(pts, s[0],s[1],s[2],align=False) pts = aff.Translate(pts,t[0],t[1],t[2],align=False) path = pts H2 = ext.Extrusion0(doc1,path,spath) H = ext.GraphUnionS(H1,H2) return H
degrees = 0 axis = [0,1,0] q = aff.HH.rotation_quaternion(degrees,axis[0],axis[1],axis[2]) scale = 1. s = [scale,scale,scale] # the same scale as previous for caps t = [-80,0,50.] pts = H0['pts'] q = aff.HH.rotation_quaternion(degrees,axis[0],axis[1],axis[2]) C = aff.Center(pts) pts = aff.Translate(pts,-C[0],-C[1],-C[2],align=False) pts = aff.Rotate(pts,q,align=False) pts = aff.Scale(pts, s[0],s[1],s[2],align=False) pts = aff.Translate(pts,t[0],t[1],t[2],align=False) H0['pts'] = pts Gs = ext.Append(Gs,H0) G = ext.GraphUnionS(G,H0) # square table H1 = SquareTable1() Gs = ext.Append(Gs,H1) G = ext.GraphUnionS(G,H1) # N1 x N2 water bottles N1 = 1 N2 = 1 for j in range(N2): for i in range(N1): H2 = rc.WaterBottle(n=10) degrees = -90 axis = [0,1,0] q = aff.HH.rotation_quaternion(degrees,axis[0],axis[1],axis[2])
G = {} G['V'] = [] G['E'] = [] G['F'] = [] G['N'] = [] G['pts'] = [] Gs = [] # Ellipsoid Object r = 10 # radius of cross section a = 50 # radius of helix, must be big enough b = 10 # pitch t = [-80., 0., 50.] degrees = 0 axis = [0, 1, 0] q = aff.HH.rotation_quaternion(degrees, axis[0], axis[1], axis[2]) scale = 1. s = [scale, scale, scale] # the same scale as previous for caps # n is length H0 = he.Helix(r, a, b, t, q, s, m=10, n=20, N=10) Gs = ext.Append(Gs, H0) G = ext.GraphUnionS(G, H0) ################################# # Save Scene 1 ext.Graphs2OBJ(BIGDATA + "Helix2.obj", Gs, "scene") # Double-Click on OBJ file import os os.system(BIGDATA + "Helix2.obj")
degrees = 0 axis = [0,1,0] q = aff.HH.rotation_quaternion(degrees,axis[0],axis[1],axis[2]) scale = 1. s = [scale,scale,scale] # the same scale as previous for caps t = [-80,0,50.] pts = H0['pts'] q = aff.HH.rotation_quaternion(degrees,axis[0],axis[1],axis[2]) C = aff.Center(pts) pts = aff.Translate(pts,-C[0],-C[1],-C[2],align=False) pts = aff.Rotate(pts,q,align=False) pts = aff.Scale(pts, s[0],s[1],s[2],align=False) pts = aff.Translate(pts,t[0],t[1],t[2],align=False) H0['pts'] = pts Gs = ext.Append(Gs,H0) G = ext.GraphUnionS(G,H0) # square table H1 = SquareTable1() Gs = ext.Append(Gs,H1) G = ext.GraphUnionS(G,H1) # coffee cup Hcc = CoffeeCup() degrees = 0 axis = [0,1,0] q = aff.HH.rotation_quaternion(degrees,axis[0],axis[1],axis[2]) scale = 1. s = [scale,scale,scale] # the same scale as previous for caps t = [100,0,30.] pts = Hcc['pts']
BIGDATA = r"C:/_BigData/_3D/my_scenes/" G = {} G['V'] = [] G['E'] = [] G['F'] = [] G['N'] = [] G['pts'] = [] Gs = [] w, h, d = 10, 10, 10 degrees = 90 axis = [0, 0, 1] q = ext.aff.HH.rotation_quaternion(degrees, axis[0], axis[1], axis[2]) t = [-50, 0, 0] s = [1, 1, 1] G2 = ext.CubeObj(w, h, d, t, q, s) Gs = ext.Append(Gs, G2) G = ext.GraphUnionS(G, G2) #H = Parabola() H = ext.TrefoilKnot() Gs = ext.Append(Gs, H) G = ext.GraphUnionS(G, H) ext.Graph2OBJ(BIGDATA + "extrude-1.obj", G, "scene") import os print("Open extrude-1.obj with 3D Viewer by double-clicking on it") os.system(BIGDATA + "extrude-1.obj")
t = deepcopy(goal) degrees = 90 axis = [0, 0, 1] q = aff.HH.rotation_quaternion(degrees, axis[0], axis[1], axis[2]) scale = 3. s = [scale, scale, scale] # the same scale as previous for caps H1 = rc.WaterBottle(n=30) pts = H1['pts'] C = aff.Center(pts) pts = aff.Translate(pts, -C[0], -C[1], -C[2], align=False) pts = aff.Rotate(pts, q, align=False) pts = aff.Scale(pts, s[0], s[1], s[2], align=False) pts = aff.Translate(pts, t[0], t[1], t[2], align=False) H1['pts'] = pts Gs = ext.Append(Gs, H1) G = ext.GraphUnionS(G, H1) N = 10 degrees = 0 axis = [0, 1, 0] qp = aff.HH.rotation_quaternion(degrees, axis[0], axis[1], axis[2]) scale = 1. sp = [scale, scale, scale] # the same scale as previous for caps for i in range(N): Puma560.P, flag = Puma560.Reach(Puma560.P, goal) print(i, flag, Puma560.P.Start()) G1 = Puma560.P.Graph() H2 = BodyGraph(G, Gs, G1, Puma560.P.pt, qp, sp) Gs = ext.Append(Gs, H2) G = ext.GraphUnionS(G, H2)