def morph(clm1, clm2, t, lmax): """Interpolate linearly the two sets of sph harm. coeeficients.""" clm = (1 - t) * clm1 + t * clm2 grid_reco = clm.expand(lmax=lmax) # cut "high frequency" components agrid_reco = grid_reco.to_array() pts = [] for i, longs in enumerate(agrid_reco): ilat = grid_reco.lats()[i] for j, value in enumerate(longs): ilong = grid_reco.lons()[j] th = np.deg2rad(90 - ilat) ph = np.deg2rad(ilong) r = value + rbias p = np.array([sin(th) * cos(ph), sin(th) * sin(ph), cos(th)]) * r pts.append(p) return pts
def derivs(state, t): dydx = np.zeros_like(state) dydx[0] = state[1] a = state[2] - state[0] sina, cosa = sin(a), cos(a) den1 = (M1 + M2) * L1 - M2 * L1 * cosa * cosa dydx[1] = (M2 * L1 * state[1] * state[1] * sina * cosa + M2 * G * sin(state[2]) * cosa + M2 * L2 * state[3] * state[3] * sina - (M1 + M2) * G * sin(state[0])) / den1 dydx[2] = state[3] den2 = (L2 / L1) * den1 dydx[3] = (-M2 * L2 * state[3] * state[3] * sina * cosa + (M1 + M2) * G * sin(state[0]) * cosa - (M1 + M2) * L1 * state[1] * state[1] * sina - (M1 + M2) * G * sin(state[2])) / den2 return dydx
def makeGrid(shape, N): rmax = 2.0 # line length agrid, pts = [], [] for th in np.linspace(0, np.pi, N, endpoint=True): lats = [] for ph in np.linspace(0, 2 * np.pi, N, endpoint=True): p = np.array([sin(th) * cos(ph), sin(th) * sin(ph), cos(th)]) * rmax intersections = shape.intersectWithLine([0, 0, 0], p) if len(intersections): value = mag(intersections[0]) lats.append(value - rbias) pts.append(intersections[0]) else: lats.append(rmax - rbias) pts.append(p) agrid.append(lats) agrid = np.array(agrid) actor = Points(pts, c="k", alpha=0.4, r=1) return agrid, actor
""" Example usage of addTrail(). Add a trailing line to a moving object. """ print(__doc__) from vedo import Plotter, sin, Sphere, Point vp = Plotter(axes=6, interactive=False) s = Sphere().c("green").bc("tomato") s.cutWithPlane([-0.9, 0, 0]) # cut left part of sphere p = Point([1, 1, 1], r=12, c="black") # add a trail to point p with max length 0.5 and 50 segments p.addTrail(lw=3, maxlength=0.5, n=50) # add meshes to Plotter list vp += [s, p] for i in range(200): p.pos(-2 + i / 100.0, sin(i / 5.0) / 15, 0) vp.camera.Azimuth(-0.2) vp.show() vp.show(interactive=True)
# for i, j in G.edges(): g.addEdge(j,i) ##################### Manually create nodes and edges for i in range(6): g.addChild(i) # add one child node to node i for i in range(3): g.addChild(i) for i in range(3): g.addChild(i) for i in range(7,9): g.addChild(i) for i in range(3): g.addChild(12) # add 3 children to node 12 g.addEdge(1,16) ##################### build and draw graph = g.build().unpack(0).lineWidth(4) # get the vedo 3d graph lines nodes = graph.points() # get the 3d points of the nodes pts = Points(nodes, r=10).lighting('off') v1 = ['node'+str(n) for n in range(len(nodes))] v2 = [sin(x) for x in range(len(nodes))] labs1 = pts.labels(v1, scale=.04, italic=True).addPos(.05,0.04,0).c('green') labs2 = pts.labels(v2, scale=.04, precision=3).addPos(.05,-.04,0).c('red') # Interpolate the node value to color the edges: graph.cmap('viridis', v2).addScalarBar3D(c='k').addPos(.3,0,0) pts.cmap('viridis', v2) # This would colorize the edges directly with solid color based on a v3 array: # v3 = [sin(x) for x in range(graph.NCells())] # graph.cmap('jet', v3).addScalarBar() show(pts, graph, labs1, labs2, __doc__, axes=9)
sin(state[2]) * cosa + M2 * L2 * state[3] * state[3] * sina - (M1 + M2) * G * sin(state[0])) / den1 dydx[2] = state[3] den2 = (L2 / L1) * den1 dydx[3] = (-M2 * L2 * state[3] * state[3] * sina * cosa + (M1 + M2) * G * sin(state[0]) * cosa - (M1 + M2) * L1 * state[1] * state[1] * sina - (M1 + M2) * G * sin(state[2])) / den2 return dydx t = np.arange(0.0, 10.0, dt) state = np.radians([th1, w1, th2, w2]) y = integrate.odeint(derivs, state, t) P1 = np.dstack([L1 * sin(y[:, 0]), -L1 * cos(y[:, 0])]).squeeze() P2 = P1 + np.dstack([L2 * sin(y[:, 2]), -L2 * cos(y[:, 2])]).squeeze() ax = Axes(xrange=(-2, 2), yrange=(-2, 1), htitle=__doc__) pb = ProgressBar(0, len(t), c="b") for i in pb.range(): j = max(i - 5, 0) k = max(i - 10, 0) l1 = Line([[0, 0], P1[i], P2[i]]).lw(7).c("blue2") l2 = Line([[0, 0], P1[j], P2[j]]).lw(6).c("blue2", 0.3) l3 = Line([[0, 0], P1[k], P2[k]]).lw(5).c("blue2", 0.1) pt = Points([P1[i], P2[i], P1[j], P2[j], P1[k], P2[k]], r=8).c("blue2", 0.2) show(l1, l2, l3, pt, ax, interactive=False, size=(900, 700), zoom=1.4) pb.print()