Exemplo n.º 1
0
    y_eu, v_eu = euler(y_eu, v_eu, t, dt)
    y_rk, v_rk = rk4(y_rk, v_rk, t, dt)
    t += dt
    positions_eu.append(y_eu)  # store result of integration
    positions_rk.append(y_rk)
    pb.print("Integrate: RK-4 and Euler")

####################################################
# Visualize the result
####################################################
vp = Plotter(interactive=0, axes=2)  # choose axes type nr.2
vp.ytitle = "u(x,t)"
vp.ztitle = ""  # will not draw z axis

for i in x:
    vp += Point([i, 0, 0], c="green", r=6)
pts_actors_eu = vp.actors  # save a copy of the actors list
pts_actors_eu[0].legend = "Euler method"

vp.actors = []  # clean up the list

for i in x:
    vp += Point([i, 0, 0], c="red", r=6)
pts_actors_rk = vp.actors  # save a copy of the actors list
pts_actors_rk[0].legend = "Runge-Kutta4"

# merge the two lists and set it as the current actors
vp.actors = pts_actors_eu + pts_actors_rk

# let's also add a fancy background image from wikipedia
vp.load(datadir + "images/wave_wiki.png",
Exemplo n.º 2
0
"""
Text jutification and positioning.
 (center, top-left, top-right, bottom-left, bottom-right)
"""
print(__doc__)
from vtkplotter import show, Text, Point

txt = "I like\nto play\nguitar"

tx = Text(txt, pos=[1, 2, 0], s=0.2, c=3, bc=1, depth=0.2, justify="top-left")
to = Point([1, 2, 0], c="r")  # mark text origin
ax = Point([0, 0, 0])  # mark axes origin

show(tx, to, ax, axes=8, verbose=0)
Exemplo n.º 3
0
    y_eu, v_eu = euler(y_eu, v_eu, t, dt)
    y_rk, v_rk = rk4(y_rk, v_rk, t, dt)
    t += dt
    positions_eu.append(y_eu)  # store result of integration
    positions_rk.append(y_rk)
    pb.print("Integrate: RK-4 and Euler")

####################################################
# Visualize the result
####################################################
vp = Plotter(interactive=0, axes=2, bg="w")  # choose axes type nr.2
vp.ytitle = "u(x,t)"
vp.ztitle = ""  # will not draw z axis

for i in x:
    vp.add(Point([i, 0, 0], c="green", r=6))
pts_actors_eu = vp.actors  # save a copy of the actors list
pts_actors_eu[0].legend = "Euler method"

vp.actors = []  # clean up the list

for i in x:
    vp.add(Point([i, 0, 0], c="red", r=6))
pts_actors_rk = vp.actors  # save a copy of the actors list
pts_actors_rk[0].legend = "Runge-Kutta4"

# merge the two lists and set it as the current vtkPlotter actors
vp.actors = pts_actors_eu + pts_actors_rk

# let's also add a fancy background image from wikipedia
vp.load(datadir + "images/wave_wiki.png",
Exemplo n.º 4
0
from vtkplotter import Latex, Point, show

# https://matplotlib.org/tutorials/text/mathtext.html

latex1 = r'x= \frac{ - b \pm \sqrt {b^2 - 4ac} }{2a}'
latex2 = r'\mathcal{A}\mathrm{sin}(2 \omega t)'
latex3 = r'I(Y | X)=\sum_{x \in \mathcal{X}, y \in \mathcal{Y}} p(x, y) \log \left(\frac{p(x)}{p(x, y)}\right)'
latex4 = r'\Gamma_{\epsilon}(x)=\left[1-e^{-2 \pi \epsilon}\right]^{1-x} \prod_{n=0}^{\infty} \frac{1-\exp (-2 \pi \epsilon(n+1))}{1-\exp (-2 \pi \epsilon(x+n))}'
latex5 = r'\left( \begin{array}{l}{c t^{\prime}} \\ {x^{\prime}} \\ {y^{\prime}} \\ {z^{\prime}}\end{array}\right)=\left( \begin{array}{cccc}{\gamma} & {-\gamma \beta} & {0} & {0} \\ {-\gamma \beta} & {\gamma} & {0} & {0} \\ {0} & {0} & {1} & {0} \\ {0} & {0} & {0} & {1}\end{array}\right) \left( \begin{array}{l}{c t} \\ {x} \\ {y} \\ {z}\end{array}\right)'
latex6 = r'\mathrm{CO}_{2}+6 \mathrm{H}_{2} \mathrm{O} \rightarrow \mathrm{C}_{6} \mathrm{H}_{12} \mathrm{O}_{6}+6 \mathrm{O}_{2}'
latex7 = r'x \mathrm{(arb. units)}'

l = Latex(latex4,
          s=1,
          c='white',
          bg='',
          alpha=0.9,
          usetex=False,
          fromweb=False)
l.crop(0.3, 0.3)  # crop top and bottom 30%
l.pos(2, 0, 0)

p = Point()
box = l.box()  # return the bounding box of an actor

show(p, l, box, axes=8)
Exemplo n.º 5
0
        R12 = Pos[s2]-Pos[s1]
        nR12 = np.linalg.norm(R12)
        d12 = Radius[s1]+Radius[s2] - nR12
        tau = R12/nR12
        DR0 = d12*tau
        x1 = Mass[s1]/(Mass[s1]+Mass[s2])
        x2 = 1-x1                 # x2 = Mass[s2]/(Mass[s1]+Mass[s2])
        Pos[s1] -= x2*DR0
        Pos[s2] += x1*DR0
        DV0 = 2*dot(Vel[s2]-Vel[s1], tau)*tau
        Vel[s1] +=  x2*DV0
        Vel[s2] -=  x1*DV0

    # Update the location of the spheres
    for s in range(Nsp): Spheres[s].pos([Pos[s][0],Pos[s][1],0])
        
    if not int(i)%10:                   # every ten steps:
        rsp = [Pos[0][0],Pos[0][1],0]
        rsv = [Vel[0][0],Vel[0][1],0]
        vp.add(Point(rsp, c='r', r=5, alpha=0.1))  # leave a point trace
        vp.show()                    # render scene   
    pb.print('#actors='+str(len(vp.actors)))
    
vp.show(interactive=1)






Exemplo n.º 6
0
from vtkplotter import Plotter, mag, Points, Point
import numpy as np

dt = 0.002
y = [25.0, -10.0, -7.0]  # Starting point (initial condition)
pts, cols = [], []

for t in np.linspace(0, 20, int(20 / dt)):
    # Integrate a funny differential equation
    dydt = np.array([
        -8 / 3.0 * y[0] + y[1] * y[2], -10.0 * (y[1] - y[2]),
        -y[1] * y[0] + 28.0 * y[1] - y[2]
    ])
    y = y + dydt * dt

    c = np.clip([mag(dydt) * 0.005], 0, 1)[0]  # color by speed
    pts.append(y)
    cols.append([c, 0, 1 - c])

scene = Plotter(title="Lorenz attractor", axes=2, verbose=0, bg="w")
scene.add(Point(y, r=20, c="g", alpha=0.3))
scene.add(Points(pts, r=5, c=cols, alpha=0.3))
scene.show()
Exemplo n.º 7
0
import numpy as np

dt = 0.002
y = (25.0, -10.0, -7.0)  # Starting point (initial condition)
pts, cols = [], []

for t in np.linspace(0, 20, int(20 / dt)):
    # Integrate a funny differential equation
    dydt = np.array([
        -8 / 3.0 * y[0] + y[1] * y[2], -10.0 * (y[1] - y[2]),
        -y[1] * y[0] + 28.0 * y[1] - y[2]
    ])
    y = y + dydt * dt

    c = np.clip([np.linalg.norm(dydt) * 0.005], 0, 1)[0]  # color by speed
    cols.append([c, 0, 1 - c])
    pts.append(y)

from vtkplotter import Plotter, Line, Point, Points, settings
settings.renderPointsAsSpheres = False  # render points as squares

scene = Plotter(title="Lorenz attractor", axes=1, verbose=0, bg="w")
scene += Point(y, r=10, c="g")  # end point
scene += Points(pts, r=3, c=cols)
scene += Line(pts).off().addShadow(x=3)  # only show shadow, not line
scene += Line(pts).off().addShadow(z=-30)
scene.show(viewup='z')
Exemplo n.º 8
0
from vtkplotter import Plotter, mag, Points, Point
import numpy as np

dt = 0.002
y = [25.0, -10.0, -7.0]  # Starting point (initial condition)
pts, cols = [], []

for t in np.linspace(0, 20, int(20 / dt)):
    # Integrate a funny differential equation
    dydt = np.array([
        -8 / 3.0 * y[0] + y[1] * y[2], -10.0 * (y[1] - y[2]),
        -y[1] * y[0] + 28.0 * y[1] - y[2]
    ])
    y = y + dydt * dt

    c = np.clip([mag(dydt) * 0.005], 0, 1)[0]  # color by speed
    pts.append(y)
    cols.append([c, 0, 1 - c])

scene = Plotter(title="Lorenz attractor", axes=2, verbose=0, bg="w")
scene += Point(y, r=20, c="g")
scene += Points(pts, r=5, c=cols)
scene.show()
Exemplo n.º 9
0
"""
Text jutification and positioning:
 top-left, top-right, bottom-left, bottom-right,
 center-left, center-right, center-left, center-right
"""
print(__doc__)
from vtkplotter import show, Text, Point

txt = "Text\njustification\n& position"

pos = [1, 2, 0]

tx = Text(txt, pos, s=1, depth=0.1, justify="bottom-left")

t0 = Point(pos, c="r")  # mark text position
ax = Point(c="blue")  # mark axes origin

show(tx, tx.box().c("y"), t0, ax, axes=8, bg="lb", size=(500, 500))
Exemplo n.º 10
0
from vtkplotter import Plotter, mag, Points, Point
import numpy as np


dt = 0.002
y = [25., -10., -7.] # Starting point (initial condition)
pts, cols = [], []


for t in np.linspace(0,20, int(20/dt)):
  # Integrate a funny differential equation
  dydt = np.array([-8/3.*y[0]+ y[1]*y[2], 
                   -10.*(y[1]-y[2]), 
                   -y[1]*y[0]+28.*y[1]-y[2]])
  y = y + dydt * dt

  c = np.clip( [mag(dydt) * 0.005], 0, 1)[0] # color by speed
  pts.append(y)
  cols.append([c,0, 1-c])

scene = Plotter(title='Lorenz attractor', axes=2, verbose=0, bg='w')
scene.add(Point(y, r=20, c='g', alpha=0.3))
scene.add(Points(pts, r=5, c=cols, alpha=0.3))
scene.show()

Exemplo n.º 11
0
'''
Example usage of addTrail(). Add a triling line to a moving object.
'''
print(__doc__)
from vtkplotter import Plotter, sin, Sphere, Point

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

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

p = Point([1, 1, 1], r=12, c='k')

# 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)
vp.add([s, p])

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

vp.show(interactive=1)
    y_eu, v_eu = euler(y_eu, v_eu, t, dt)
    y_rk, v_rk = rk4(y_rk, v_rk, t, dt)
    t += dt
    positions_eu.append(y_eu)  # store result of integration
    positions_rk.append(y_rk)
    pb.print('Integrate: RK-4 and Euler')

####################################################
# Visualize the result
####################################################
vp = Plotter(interactive=0, axes=2, bg='w')  # choose axes type nr.2
vp.ytitle = 'u(x,t)'
vp.ztitle = ''  # will not draw z axis

for i in x:
    vp.add(Point([i, 0, 0], c='green', r=6))
pts_actors_eu = vp.actors  # save a copy of the actors list
pts_actors_eu[0].legend = 'Euler method'

vp.actors = []  # clean up the list

for i in x:
    vp.add(Point([i, 0, 0], c='red', r=6))
pts_actors_rk = vp.actors  # save a copy of the actors list
pts_actors_rk[0].legend = 'Runge-Kutta4'

# merge the two lists and set it as the current vtkPlotter actors
vp.actors = pts_actors_eu + pts_actors_rk

# let's also add a fancy background image from wikipedia
vp.load('data/images/wave_wiki.png', alpha=.8).scale(0.4).pos([0, -100, -20])
Exemplo n.º 13
0
from vtkplotter import Plotter, mag, Points, Point
import numpy as np

dt = 0.002
y = [25.0, -10.0, -7.0]  # Starting point (initial condition)
pts, cols = [], []

for t in np.linspace(0, 20, int(20 / dt)):
    # Integrate a funny differential equation
    dydt = np.array([
        -8 / 3.0 * y[0] + y[1] * y[2], -10.0 * (y[1] - y[2]),
        -y[1] * y[0] + 28.0 * y[1] - y[2]
    ])
    y = y + dydt * dt

    c = np.clip([mag(dydt) * 0.005], 0, 1)[0]  # color by speed
    pts.append(y)
    cols.append([c, 0, 1 - c])

scene = Plotter(title="Lorenz attractor", axes=2, verbose=0, bg="w")
scene += Point(y, r=20, c="g", alpha=0.3)
scene += Points(pts, r=5, c=cols, alpha=0.3)
scene.show()
Exemplo n.º 14
0
"""
Mark a specific point on a mesh with some text.
"""
from vtkplotter import Sphere, Point, show, Text

sp = Sphere().wire(True)

pcoords = sp.getPoint(144)

pt = Point(pcoords, r=12, c='white')

tx = Text('my fave\npoint',
          pcoords,
          s=0.1,
          c='lightblue',
          bc='green',
          followcam=False)

show([sp, pt, tx, Text(__doc__)], verbose=0)
Exemplo n.º 15
0
"""
Example usage of addTrail().
Add a trailing line to a moving object.
"""
print(__doc__)
from vtkplotter import Plotter, sin, Sphere, Point

vp = Plotter(axes=6, bg='white', interactive=0)

s = Sphere(c="green", res=24)
s.cutWithPlane([-0.9, 0, 0], showcut=True)  # cut left part of sphere

p = Point([1, 1, 1], r=12, c="k")

# 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)
vp += [s, p]

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

vp.show(interactive=1)
Exemplo n.º 16
0
    # Check to see if the spheres are colliding
    for ij in hitlist:
        s1, s2 = divmod(ij, Nsp)  # decode the spheres pair (s1,s2) colliding
        hitlist.remove(s2 * Nsp +
                       s1)  # remove symmetric (s2,s1) pair from list
        R12 = Pos[s2] - Pos[s1]
        nR12 = np.linalg.norm(R12)
        d12 = Radius[s1] + Radius[s2] - nR12
        tau = R12 / nR12
        DR0 = d12 * tau
        x1 = Mass[s1] / (Mass[s1] + Mass[s2])
        x2 = 1 - x1  # x2 = Mass[s2]/(Mass[s1]+Mass[s2])
        Pos[s1] -= x2 * DR0
        Pos[s2] += x1 * DR0
        DV0 = 2 * dot(Vel[s2] - Vel[s1], tau) * tau
        Vel[s1] += x2 * DV0
        Vel[s2] -= x1 * DV0

    # Update the location of the spheres
    for s in range(Nsp):
        Spheres[s].pos([Pos[s][0], Pos[s][1], 0])

    if not int(i) % 10:  # every ten steps:
        rsp = [Pos[0][0], Pos[0][1], 0]
        rsv = [Vel[0][0], Vel[0][1], 0]
        vp += Point(rsp, c="r", r=5, alpha=0.1)  # leave a point trace
        vp.show()  # render scene
    pb.print()

vp.show(interactive=1)
Exemplo n.º 17
0
"""
Mark a specific point 
on a mesh with some text.
"""
from vtkplotter import Sphere, Point, show, Text

sp = Sphere().wire(True)

pcoords = sp.getPoint(144)

pt = Point(pcoords, r=12, c="white")

tx = Text("my fave\npoint",
          pcoords,
          s=0.1,
          c="lightblue",
          bc="green",
          followcam=False)

show(sp, pt, tx, Text(__doc__), axes=1)
Exemplo n.º 18
0
In this example we modify the mesh of a shape
by moving the points along the normals to the surface
and along the radius of a sphere centered at the center of mass.
At each step we redefine the actor so that the normals are
recalculated for the underlying polydata.
'''
from __future__ import division, print_function
from vtkplotter import Plotter, norm, mag, settings, Point, Text

settings.computeNormals = True  # on object creation by default

vp = Plotter(axes=0, verbose=0, bg='w')

s = vp.load('data/290.vtk', c='red', bc='plum')
c = s.centerOfMass()
vp.add(Point(c))

Niter = 4
for t in range(Niter):
    print('iteration', t)
    coords = s.coordinates()
    normals = s.normals()
    aves = s.averageSize() * 1.5

    for i in range(s.N()):
        n = normals[i]
        p = coords[i]
        q = norm(p - c) * aves + c
        dp = mag(q - p)
        alongn = n * dp
        alongr = q - p  # bias normal