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 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
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
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()