.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/topology/curves/plot_01_gauss_linking_number.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 or to run this example in your browser via JupyterLite. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_topology_curves_plot_01_gauss_linking_number.py: Gauss's linking number (1833) ============================= Gauss's double integral :math:`\frac{1}{4\pi}\oint\oint \frac{(r_1 - r_2)\cdot(dr_1 \times dr_2)}{|r_1 - r_2|^3}` counts how many times one closed curve winds around another. It is an integer that no deformation can change without passing one curve through the other. Below: the unlink (0), the Hopf link (:math:`\pm 1`, the sign set by the orientations), and torus links whose components wind :math:`n` times around each other. .. GENERATED FROM PYTHON SOURCE LINES 15-40 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from mathematicskit.topology import linking_number t = np.linspace(0, 2 * np.pi, 300, endpoint=False) ring = np.column_stack([np.cos(t), np.sin(t), 0 * t]) links = { "unlink": (ring, np.column_stack([3 + np.cos(t), 0 * t, np.sin(t)])), "Hopf link": (ring, np.column_stack([1 + np.cos(t), 0 * t, np.sin(t)])), "Hopf link, reversed": (ring, np.column_stack([1 + np.cos(t), 0 * t, np.sin(t)])[::-1]), } def torus_link(n, phase): v = n * t + phase return np.column_stack([(2 + np.cos(v)) * np.cos(t), (2 + np.cos(v)) * np.sin(t), np.sin(v)]) for n in (1, 2, 3): links[f"(2, {2 * n}) torus link"] = (torus_link(n, 0.0), torus_link(n, np.pi)) for name, (a, b) in links.items(): print(f"{name:>20}: linking number {linking_number(a, b):+.6f}") .. rst-class:: sphx-glr-script-out .. code-block:: none unlink: linking number -0.000000 Hopf link: linking number -1.000000 Hopf link, reversed: linking number +1.000000 (2, 2) torus link: linking number -1.000000 (2, 4) torus link: linking number -2.000000 (2, 6) torus link: linking number -3.000000 .. GENERATED FROM PYTHON SOURCE LINES 41-43 The links --------- .. GENERATED FROM PYTHON SOURCE LINES 43-55 .. code-block:: Python fig = plt.figure(figsize=(12, 7)) for i, (name, (a, b)) in enumerate(links.items()): ax = fig.add_subplot(2, 3, i + 1, projection="3d") for curve, color in ((a, "tab:blue"), (b, "tab:orange")): closed = np.vstack([curve, curve[:1]]) ax.plot(*closed.T, color=color, lw=2) ax.set_title(f"{name}: lk = {round(linking_number(a, b))}") ax.set_box_aspect((1, 1, 0.6)) ax.set_axis_off() fig.suptitle("Gauss (1833): the linking integral is an integer") .. image-sg:: /api/gallery/topology/curves/images/sphx_glr_plot_01_gauss_linking_number_001.png :alt: Gauss (1833): the linking integral is an integer, unlink: lk = 0, Hopf link: lk = -1, Hopf link, reversed: lk = 1, (2, 2) torus link: lk = -1, (2, 4) torus link: lk = -2, (2, 6) torus link: lk = -3 :srcset: /api/gallery/topology/curves/images/sphx_glr_plot_01_gauss_linking_number_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Text(0.5, 0.98, 'Gauss (1833): the linking integral is an integer') .. GENERATED FROM PYTHON SOURCE LINES 56-62 The integrand is a solid angle ------------------------------ Gauss read the integral as the solid angle swept by the direction from one curve to the other. Refining the polygons barely changes the sum, which stays an integer: it is exact for polygons, not an approximation. .. GENERATED FROM PYTHON SOURCE LINES 62-69 .. code-block:: Python ns = [12, 24, 48, 96, 192] values = [] for n in ns: s = np.linspace(0, 2 * np.pi, n, endpoint=False) values.append(linking_number(np.column_stack([np.cos(s), np.sin(s), 0 * s]), np.column_stack([1 + np.cos(s), 0 * s, np.sin(s)]))) print("Hopf link with n-gon curves:", np.round(values, 12)) .. rst-class:: sphx-glr-script-out .. code-block:: none Hopf link with n-gon curves: [-1. -1. -1. -1. -1.] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.197 seconds) .. _sphx_glr_download_api_gallery_topology_curves_plot_01_gauss_linking_number.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../../../lite/lab/index.html?path=api/gallery/topology/curves/plot_01_gauss_linking_number.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_gauss_linking_number.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_gauss_linking_number.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_gauss_linking_number.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_