.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/complex_analysis/conformal_maps/plot_03_mobius_circles.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_complex_analysis_conformal_maps_plot_03_mobius_circles.py: Möbius transformations map circles to circles ============================================= August Ferdinand Möbius's 1855 theory of *Kreisverwandtschaft* ("circle relationship") studied the maps :math:`w = (az + b)/(cz + d)`, :math:`ad - bc \ne 0`. Every one of them sends circles and lines to circles and lines, where a line is a circle through :math:`\infty`. This script maps a family of circles and checks that each image is again a circle by fitting one to it. .. GENERATED FROM PYTHON SOURCE LINES 14-32 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from mathematicskit.complex_analysis import circle_contour, mobius_transform a, b, c, d = 1.0, -0.5j, 0.6, 1.0 + 0.3j def fit_circle(points): """Least-squares circle x^2 + y^2 + Dx + Ey + F = 0; returns center, radius, max residual.""" x, y = points.real, points.imag A = np.column_stack([x, y, np.ones_like(x)]) D, E, F = np.linalg.lstsq(A, -(x**2 + y**2), rcond=None)[0] center = complex(-D / 2, -E / 2) radius = np.sqrt(abs(center) ** 2 - F) return center, radius, np.max(np.abs(np.abs(points - center) - radius)) .. GENERATED FROM PYTHON SOURCE LINES 33-35 Circles in the z-plane and their images --------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 35-49 .. code-block:: Python fig, (ax0, ax1) = plt.subplots(1, 2, figsize=(11, 5)) for k, (center, radius) in enumerate([(0.0, 0.5), (0.5 + 0.5j, 0.3), (-0.6, 0.4), (0.2 - 0.6j, 0.25)]): z = circle_contour(center, radius).points(400) w = mobius_transform(z, a, b, c, d) color = f"C{k}" ax0.plot(z.real, z.imag, color) ax1.plot(w.real, w.imag, color) w_center, w_radius, residual = fit_circle(w) print(f"circle {k}: image center {w_center:.4f}, radius {w_radius:.4f}, max deviation {residual:.1e}") for ax, title in ((ax0, "z-plane"), (ax1, "w = (az + b)/(cz + d)")): ax.set_aspect("equal") ax.set_title(title) .. image-sg:: /api/gallery/complex_analysis/conformal_maps/images/sphx_glr_plot_03_mobius_circles_001.png :alt: z-plane, w = (az + b)/(cz + d) :srcset: /api/gallery/complex_analysis/conformal_maps/images/sphx_glr_plot_03_mobius_circles_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none circle 0: image center -0.3000-0.5000j, radius 0.5831, max deviation 8.9e-16 circle 1: image center 0.2954-0.1487j, radius 0.1734, max deviation 4.7e-16 circle 2: image center -1.4253-0.3167j, radius 1.0554, max deviation 1.1e-15 circle 3: image center 0.2044-0.9875j, radius 0.2360, max deviation 2.1e-15 .. GENERATED FROM PYTHON SOURCE LINES 50-52 A circle through the pole -d/c becomes a line --------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 52-62 .. code-block:: Python pole = -d / c theta = np.linspace(0.0, 2.0 * np.pi, 401)[1:-1] # theta = 0 is the pole itself z = pole + 0.5 * (1.0 - np.exp(1j * theta)) w = mobius_transform(z, a, b, c, d) p, q = w[100], w[300] # two finite image points fix the line distance = np.abs(((w - p) * np.conj(q - p)).imag) / abs(q - p) print(f"max distance of the images from the line through two of them: {np.max(distance / np.maximum(1.0, np.abs(w))):.1e} (relative)") plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none max distance of the images from the line through two of them: 1.8e-14 (relative) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.117 seconds) .. _sphx_glr_download_api_gallery_complex_analysis_conformal_maps_plot_03_mobius_circles.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/complex_analysis/conformal_maps/plot_03_mobius_circles.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_mobius_circles.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_mobius_circles.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_mobius_circles.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_