Exemplo n.º 1
0
# Example usage of addTrail()
#
from vtkplotter import Plotter, sin

vp = Plotter(axes=6)

s = vp.sphere(c='green', res=24)
vp.cutPlane(s, [-0.9, 0, 0], showcut=True)  #cut left part of sphere

p = vp.point([1, 1, 1], r=12)

# add a trail to point p with maximum length 0.5 and 50 segments
p.addTrail(c='k', lw=3, maxlength=0.5, n=50)

for i in range(200):
    p.pos([-2 + i / 100., sin(i / 5.) / 15, 0])
    vp.render()
    vp.camera.Azimuth(-0.2)

vp.show(resetcam=0)
Exemplo n.º 2
0
phidot = 0      # (try -1 and +1 to get first and second pattern)

# ############################################################ 
g, r = 9.81, Lshaft/2      
I3 = 1/2*M*R**2      # moment of inertia, I, of gyroscope about its own axis
I1 = M*r**2 + 1/2*I3 # I about a line through the support, perpendicular to axis
phi = psi = thetadot = 0
x = vector(theta, phi, psi) # Lagrangian coordinates
v = vector(thetadot, phidot, psidot)

# ############################################################ the scene
vp = Plotter(verbose=0, axes=3, interactive=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
Exemplo n.º 3
0
vp.ring(c='g', r=RingRadius, thickness=RingThickness, alpha=.1,
        wire=1)  ### <--

Atoms = []
poslist = []
plist, mlist, rlist = [], [], []
mass = Matom * Ratom**3 / Ratom**3
pavg = np.sqrt(2. * mass * 1.5 * k *
               T)  # average kinetic energy p**2/(2mass) = (3/2)kT

for i in range(Natoms):
    alpha = 2 * np.pi * random()
    x = RingRadius * np.cos(alpha) * .9
    y = RingRadius * np.sin(alpha) * .9
    z = 0
    Atoms = Atoms + [vp.sphere(pos=(x, y, z), r=Ratom, c=i)]  ### <--
    theta = np.pi * random()
    phi = 2 * np.pi * random()
    px = pavg * np.sin(theta) * np.cos(phi)
    py = pavg * np.sin(theta) * np.sin(phi)
    pz = pavg * np.cos(theta)
    poslist.append((x, y, z))
    plist.append((px, py, pz))
    mlist.append(mass)
    rlist.append(Ratom)

pos = np.array(poslist)
poscircle = pos
p = np.array(plist)
m = np.array(mlist)
m.shape = (Natoms, 1)
Exemplo n.º 4
0
# Shrink the triangulation of a mesh to make the inside visible
#
from vtkplotter import Plotter

vp = Plotter()

vp.load('data/shapes/teapot.vtk').shrink(0.8)

vp.sphere(r=0.2).pos([0, 0, -0.5])

vp.show(viewup='z', zoom=1.2)
Exemplo n.º 5
0
a2 = a1.subdivide(method=0)  # Increasing the number of points of the mesh
coords2 = a2.coordinates()
pts2 = vp.points(coords2, r=1, legend='#points = ' + str(len(coords2)))
vp.show([a2, pts2], at=1, interactive=True)

########################################################################################
# Draw a bunch of simple objects on separate parts of the rendering window:
# split window to best accomodate 9 renderers
vp = Plotter(N=9, title='basic shapes')
vp.sharecam = False  # each object can be moved independently
vp.show(at=0, actors=vp.arrow([0, 0, 0], [1, 1, 1]), legend='arrow')
vp.show(at=1, actors=vp.line([0, 0, 0], [1, 1, 1]), legend='line')
vp.show(at=2, actors=vp.points([[0, 0, 0], [1, 1, 1]]), legend='points')
vp.show(at=3, actors=vp.text('Hello!'))
vp.show(at=4, actors=vp.sphere())
vp.show(at=5, actors=vp.cube(), legend='cube')
vp.show(at=6, actors=vp.ring(), legend='ring')
vp.show(at=7, actors=vp.helix(), legend='helix')
vp.show(at=8, actors=vp.cylinder(), legend='cylinder', interactive=1)

########################################################################################
# Draw a bunch of objects from various mesh formats. Loading is automatic.
vp = Plotter(shape=(3, 3),
             title='mesh formats')  # split window in 3 rows and 3 columns
vp.sharecam = False  # each object can be moved independently
vp.show('data/beethoven.ply', at=0, c=0, axes=0,
        ruler=1)  # dont show axes, add a ruler
vp.show('data/cow.g', at=1, c=1, zoom=1.15)  # make it 15% bigger
vp.show('data/limb.pcd', at=2, c=2)
vp.show('data/ring.gmsh', at=3, c=3, wire=1)
Exemplo n.º 6
0
    ListPos.append(PossiblePos[n])
    del PossiblePos[n]
Pos = np.array(ListPos)

# Create an array with all the radius and a list with all the masses
Radius = np.concatenate((np.array([Rb]), np.array([Rs] * (Nsp - 1))))
Mass = [1.0] + [Ms] * (Nsp - 1)

# Create the initial array of velocities at random with big sphere at rest
ListVel = [(0., 0.)]
for s in range(1, Nsp):
    ListVel.append((Rb * random.uniform(-1, 1), Rb * random.uniform(-1, 1)))
Vel = np.array(ListVel)

# Create the spheres
Spheres = [vp.sphere(pos=(Pos[0][0], Pos[0][1], 0), r=Radius[0], c='red')]
for s in range(1, Nsp):
    a = vp.sphere(pos=(Pos[s][0], Pos[s][1], 0), r=Radius[s], c='blue')
    Spheres.append(a)
vp.grid(sx=screen_w, sy=screen_w)

# Auxiliary variables
Id = np.identity(Nsp)
Dij = (Radius + Radius[:, np.newaxis])**2  # Matrix Dij=(Ri+Rj)**2

# The main loop
pb = ProgressBar(0, 2000, c='r')
for i in pb.range():
    # Update all positions
    np.add(Pos, Vel * Dt, Pos)  # Fast version of Pos = Pos + Vel*Dt
Exemplo n.º 7
0
# ############################################################
g, r = 9.81, Lshaft / 2
I3 = 1 / 2 * M * R**2  # moment of inertia, I, of gyroscope about its own axis
I1 = M * r**2 + 1 / 2 * I3  # I about a line through the support, perpendicular to axis
phi = psi = thetadot = 0
x = vector(theta, phi, psi)  # Lagrangian coordinates
v = vector(thetadot, phidot, psidot)

# ############################################################ the scene
vp = Plotter(verbose=0, axes=0, interactive=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.Assembly([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],
Exemplo n.º 8
0
# Work with vtkVolume objects and surfaces.
#
from vtkplotter import vtkio, Plotter
from vtkplotter.actors import Volume

vp = Plotter()

# Load a 3D voxel dataset (returns a vtkImageData object):
img = vtkio.loadImageData('data/embryo.slc', spacing=[1, 1, 1])

# Build a vtkVolume object.
# A set of transparency values - of any length - can be passed
# to define the opacity transfer function in the range of the scalar.
#  E.g.: setting alphas=[0, 0, 0, 1, 0, 0, 0] would make visible
#  only voxels with value close to 98.5 (see print output).
vol = Volume(img, c='green', alphas=[0, 0.4, 0.9, 1])  # vtkVolume

# can relocate volume in space:
#vol.scale(0.3).pos([10,100,0]).rotate(90, axis=[0,1,1])

sph = vp.sphere(pos=[100, 100, 100], r=20)  # add a dummy surface

vp.show([vol, sph], zoom=1.4)  # show both vtkVolume and vtkActor
Exemplo n.º 9
0
    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


vp = Plotter(shape=[2,2], verbose=0, axes=3, interactive=0)

shape1 = vp.sphere(alpha=0.2)
shape2 = vp.load('data/shapes/icosahedron.vtk').normalize().lineWidth(1)

agrid1, actorpts1 = makegrid(shape1, N)
vp.show(at=0, actors=[shape1, actorpts1])

agrid2, actorpts2 = makegrid(shape2, N)
vp.show(at=1, actors=[shape2, actorpts2])
vp.camera.Zoom(1.2)
vp.interactive = False

clm1  = pyshtools.SHGrid.from_array(agrid1).expand()
clm2  = pyshtools.SHGrid.from_array(agrid2).expand()
# clm1.plot_spectrum2d() # plot the value of the sph harm. coefficients
# clm2.plot_spectrum2d() 
Exemplo n.º 10
0
# Example of boolean operations with actors or polydata
#
from vtkplotter import Plotter
from vtkplotter.analysis import booleanOperation


# declare the instance of the class
vp = Plotter(shape=(2,2), interactive=0, axes=3)

# build to sphere actors 
s1 = vp.sphere(pos=[-.7,0,0], c='r', alpha=0.5)
s2 = vp.sphere(pos=[0.7,0,0], c='g', alpha=0.5)

# make 3 different possible operations:
b1 = booleanOperation(s1, s2, 'intersect', c='m')
b2 = booleanOperation(s1, s2, 'plus', c='b', wire=True)
b3 = booleanOperation(s1, s2, 'minus', c=None)

# show the result in 4 different subwindows 0->3
vp.show([s1,s2], at=0, legend='2 spheres')
vp.show(b1, at=1, legend='intersect')
vp.show(b2, at=2, legend='plus')
vp.show(b3, at=3, legend='minus')
vp.addScalarBar() # adds a scalarbar to the last actor 
vp.show(interactive=1)
Exemplo n.º 11
0
y_dot = [0] * (N + 1)

for k in range(1, N + 1):
    alpha = np.pi / 5 * k / 10
    bob_x.append(bob_x[k - 1] + np.cos(alpha) + np.random.normal(0, .1))
    bob_y.append(bob_y[k - 1] + np.sin(alpha) + np.random.normal(0, .1))

# Create the bobs
vp = Plotter(title="Multiple Pendulum", axes=0, verbose=0)
vp.box(pos=(bob_x[0], bob_y[0], 0),
       length=12,
       width=12,
       height=.7,
       c='k',
       wire=1)
bob = [vp.sphere(pos=(bob_x[0], bob_y[0], 0), r=R / 2, c='gray')]
for k in range(1, N + 1):
    bob.append(vp.cylinder(pos=(bob_x[k], bob_y[k], 0), r=R, height=.3, c=k))

# Create the springs out of N links
link = [0] * N
for k in range(N):
    p0 = bob[k].pos()
    p1 = bob[k + 1].pos()
    link[k] = vp.helix(p0, p1, thickness=.015, r=R / 3, c='gray')

# Create some auxiliary variables
x_dot_m = [0] * (N + 1)
y_dot_m = [0] * (N + 1)
dij = [0] * (N + 1)  # array with distances to previous bob
dij_m = [0] * (N + 1)
Exemplo n.º 12
0
# Example use of addTrail() and updateTrail()
#
from vtkplotter import Plotter, sin

vp = Plotter(axes=1, interactive=0)

c = vp.cube()
vp.cutPlane(c, [-0.4, 0, 0])  #cut away the left face

s = vp.sphere([1, 1, 1], r=.03, c='db')

# add a trail to last created actor with max 50 segments
vp.addTrail(c='k', lw=3, maxlength=.5, n=50)

for i in range(200):
    s.pos([-2. + i / 100., sin(i / 5.) / 10., 0]).updateTrail()
    vp.render()
    vp.camera.Azimuth(-.3)

vp.show(interactive=1)