.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/chaos/billiards/plot_sinai_billiard.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_chaos_billiards_plot_sinai_billiard.py: Sinai Billiard (Chaotic) ======================== A billiard particle moves in a straight line at constant speed inside a closed boundary and undergoes specular reflection, :math:`\mathbf{v}' = \mathbf{v} - 2(\mathbf{v}\cdot\mathbf{n})\,\mathbf{n}`, whenever it strikes the boundary. The Sinai billiard's boundary is a square cell, :math:`|x| \le L/2,\ |y| \le L/2`, with a circular scatterer of radius :math:`r_s < L/2` removed from its center, :math:`x^2 + y^2 = r_s^2`. It is a classic example of a *defocusing* chaotic billiard: because the scatterer is convex as seen from inside the cell, it disperses nearby trajectories exponentially fast (unlike the flat walls of a Rectangle billiard, which neither focus nor defocus). This example plots a single trajectory and the resulting Poincare section, which fills densely with points rather than tracing out smooth curves. .. GENERATED FROM PYTHON SOURCE LINES 18-28 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from physicskit.chaos.systems.billiards import SinaiBilliard from physicskit.chaos.visualizers.dynamic_plots import animate_billiard_trajectory from physicskit.chaos.visualizers.phase_space import plot_billiard_trajectory, plot_poincare_section billiard = SinaiBilliard(cell_size=2.0, scatterer_radius=0.5) .. GENERATED FROM PYTHON SOURCE LINES 29-34 Animation --------- Watch the scatterer disperse the ray: notice how quickly it starts exploring the whole cell, and how the Poincare section fills in densely rather than tracing a smooth curve. .. GENERATED FROM PYTHON SOURCE LINES 34-38 .. code-block:: Python anim = animate_billiard_trajectory(billiard, pos=billiard.sample_interior_point(), vel=(0.4, 0.9), n_bounces=100, interval=50) plt.show() .. container:: sphx-glr-animation .. raw:: html .. GENERATED FROM PYTHON SOURCE LINES 39-43 To save the animation to a file instead of (or in addition to) displaying it interactively, use e.g.:: anim.save("sinai_billiard_animation.gif", writer="pillow", fps=25) .. GENERATED FROM PYTHON SOURCE LINES 45-49 Trajectory ---------- Notice how quickly the ray explores the whole cell after just a few bounces off the central scatterer. .. GENERATED FROM PYTHON SOURCE LINES 49-51 .. code-block:: Python fig, ax = plot_billiard_trajectory(billiard, pos=billiard.sample_interior_point(), vel=np.array([0.4, 0.9]), n_bounces=100) .. image-sg:: /api/gallery/chaos/billiards/images/sphx_glr_plot_sinai_billiard_002.png :alt: SinaiBilliard trajectory :srcset: /api/gallery/chaos/billiards/images/sphx_glr_plot_sinai_billiard_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 52-57 Poincare section ---------------- A single ray, given enough bounces, would already fill the section densely (this is the hallmark of ergodicity); here we pool several shorter rays for a quick illustration. .. GENERATED FROM PYTHON SOURCE LINES 57-60 .. code-block:: Python fig, ax = plot_poincare_section(billiard, n_rays=40, n_bounces=200) plt.show() .. image-sg:: /api/gallery/chaos/billiards/images/sphx_glr_plot_sinai_billiard_003.png :alt: SinaiBilliard Poincare section :srcset: /api/gallery/chaos/billiards/images/sphx_glr_plot_sinai_billiard_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 8.754 seconds) .. _sphx_glr_download_api_gallery_chaos_billiards_plot_sinai_billiard.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_sinai_billiard.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_sinai_billiard.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_sinai_billiard.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_