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 = (90 - ilat) / 57.3
            ph = ilong / 57.3
            r = value + rbias
            p = np.array([sin(th) * cos(ph), sin(th) * sin(ph), cos(th)]) * r
            pts.append(p)
    return pts
Exemplo n.º 2
0
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
Exemplo n.º 3
0
shaft = vp.cylinder([[0,0,0],         [Lshaft,0,0]], r=.03, c='dg')
rotor = vp.cylinder([[Lshaft/2.2,0,0],[Lshaft/1.8,0,0]], r=R, texture='marble')
base  = vp.sphere([     0, 0, 0], c='dg', r=.03)
tip   = vp.sphere([Lshaft, 0, 0], c='dg', r=.03)
gyro  = vp.makeAssembly([shaft, rotor, base, tip]) # group relevant actors

pedestal = vp.box([0,-0.63,0], height=.1, length=.1, width=1, texture='wood5')
pedbase  = vp.box([0,-1.13,0], height=.5, length=.5, width=.05, texture='wood5')
pedpin   = vp.pyramid([0,-.08,0], axis=[0,1,0], s=.05, height=.12, texture='wood5')
formulas = vp.load('data/images/gyro_formulas.png', alpha=.9).scale(.003).pos([-1,-1,-1.1])

# ############################################################ the physics
pb = ProgressBar(0, 4, dt, c='b')
for i, t in enumerate(pb.range()):
    st, ct, sp, cp = sin(x[0]), cos(x[0]), sin(x[1]), cos(x[1])

    thetadot, phidot, psidot = v # unpack
    atheta = st*ct*phidot**2 + (M*g*r*st-I3*(psidot+phidot*ct)*phidot*st)/I1
    aphi = (I3/I1)*(psidot+phidot*ct)*thetadot/st - 2*ct*thetadot*phidot/st
    apsi = phidot*thetadot*st - aphi*ct
    a = vector(atheta, aphi, apsi)

    v += a*dt  # update velocities   
    x += v*dt  # update Lagrangian coordinates

    gaxis = (Lshaft+0.03)*vector(st*sp, ct, st*cp)
    # set orientation along gaxis and rotate it around its axis by psidot*t degrees
    gyro.orientation(gaxis, rotation=psidot*t*57.3) 
    if not i%200: # add trace and render all, every 200 iterations
        trace = vp.point(gaxis, r=3, c='r')
Exemplo n.º 4
0
def my_z(x, y):
    return sin(2 * x * y) * cos(3 * y) / 2
##########################################################
N = 100  # number of sample points on the unit sphere
lmax = 15  # maximum degree of the expansion
rmax = 2.0  # line length
rbias = 0.5  # subtract a constant average value
x0 = [0, 0, 0]  # set object at this position
##########################################################

vp = Plotter(shape=[1, 2], verbose=0, axes=0)
shape = vp.load('data/shapes/icosahedron.vtk').normalize().pos(x0).lineWidth(2)

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)

vp.add(Points(pts, c='b', r=2))
vp.show(at=0)

############################################################
Exemplo n.º 6
0
# Form a surface by joining two lines.
#
from vtkplotter import Plotter, arange, sin, cos

vp = Plotter()

l1 = [ [sin(x),     cos(x),      x/2] for x in arange(0,9, .1)]
l2 = [ [sin(x)+0.2, cos(x)+x/15, x/2] for x in arange(0,9, .1)]

vp.tube(l1, c='g', r=0.02)
vp.tube(l2, c='b', r=0.02)

vp.ribbon(l1, l2, alpha=.2, res=(200,5), legend='ruled surf').wire(1)

vp.show(viewup='z')