.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_domains.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_auto_examples_plot_domains.py: .. currentmodule:: fdg Domain Examples =============== This example demonstrates how different domains look and behave like. .. GENERATED FROM PYTHON SOURCE LINES 9-14 .. code-block:: Python import numpy as np from fdg import Line, Quad from matplotlib import pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 15-25 Lines ----- Lines are a helper class, which map a 1D reference domain :math:`[-1, +1]` to an N-dimensional curve. :class:`Line` is represented with Bernstein polynomials, so by inserting more values between the start and end point of the line, additional knots can be added. The example bellow shows three lines, which all start and end at the same points, but with a different number of extra knots inserted. .. GENERATED FROM PYTHON SOURCE LINES 26-47 .. code-block:: Python ln1 = Line((-1, -1), (+1, +3)) ln2 = Line((-1, -1), (1, 0), (+1, +3)) ln3 = Line((-1, -1), (-1, -1), (1, 0), (+2, +3), (+1, +3)) fig, ax = plt.subplots() xplt = np.linspace(-1, +1, 101) ax.scatter(ln3.knots[:, 0], ln3.knots[:, 1], label="3", color="blue") ax.scatter(ln2.knots[:, 0], ln2.knots[:, 1], label="2", color="green") ax.scatter(ln1.knots[:, 0], ln1.knots[:, 1], label="1", color="red") ax.plot(*ln3.sample(xplt), color="blue") ax.plot(*ln2.sample(xplt), color="green") ax.plot(*ln1.sample(xplt), color="red") ax.legend() ax.set(aspect="equal") fig.tight_layout() plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_domains_001.png :alt: plot domains :srcset: /auto_examples/images/sphx_glr_plot_domains_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 48-57 Surfaces -------- A :class:`Quad` can be constructed from different lines. A quad can be bounded by lines of any order, however, each line must begin where the previous one ended and must together form a closed loop. The coordinates of the :class:`Quad` are interpolated between the curves by blending them. As such, each bounding :class:`Line` can have a different order. .. GENERATED FROM PYTHON SOURCE LINES 58-103 .. code-block:: Python bottom = Line((-1, -1), (+1, -1)) right = Line((+1, -1), (+2, 0), (+1, +1)) top = Line((+1, +1), (+1, +1), (0, -1), (-1, +1), (-1, +1)) left = Line((-1, +1), (-1.1, 0), (-0.9, 0), (-1, -1)) quad = Quad(bottom, right, top, left) fig, ax = plt.subplots() xp, yp = np.meshgrid(np.linspace(-1, +1, 11), np.linspace(-1, +1, 11)) ax.plot(*bottom.sample(xplt), color="red", label="bottom") ax.plot(*right.sample(xplt), color="green", label="right") ax.plot(*top.sample(xplt), color="blue", label="top") ax.plot(*left.sample(xplt), color="purple", label="left") ax.scatter(*quad.sample(xp, yp), color="orange", label="quad samples") ax.set(aspect="equal") ax.legend() fig.tight_layout() plt.show() # # Sub-regions # ----------- # # Domains can be sub-divided into sub-regions. This is done by specifying the # region of the reference domain to extract. For each dimension, the reference # domain reaches from -1 to +1, so the slice bellow is :math:`\frac{1}{10}` of # the width and height of the reference domain. sub_quad = quad.subregion((-0.3, -0.1), (0.5, 0.7)) fig, ax = plt.subplots() ax.scatter(*quad.sample(xp, yp), color="red", label="quad samples") ax.scatter(*sub_quad.sample(xp, yp), color="orange", label="sub-quad samples") ax.set(aspect="equal") ax.legend() fig.tight_layout() plt.show() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/images/sphx_glr_plot_domains_002.png :alt: plot domains :srcset: /auto_examples/images/sphx_glr_plot_domains_002.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_domains_003.png :alt: plot domains :srcset: /auto_examples/images/sphx_glr_plot_domains_003.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 104-110 Surfaces -------- A :class:`Line` or :class:`Quad` may be define in an any dimensional setting, as long as the space is at least 1D or 2D respectively. As such, it is entirely possible to define a :class:`Quad` as 2D surface in 3D space. .. GENERATED FROM PYTHON SOURCE LINES 111-150 .. code-block:: Python btm_part = Line( (+1, +0, -1), (+1, +1, -1), (+0, +1, -1), (-1, +1, -1), (-1, +0, -1), (-1, -1, -1), (-0, -1, -1), (+1, -1, -1), (+1, +0, -1), ) top_part = Line( (+1, +0, +1), (+1, -1, +1), (-0, -1, +1), (-1, -1, +1), (-1, +0, +1), (-1, +1, +1), (+0, +1, +1), (+1, +1, +1), (+1, +0, +1), ) stitch = Line( (+1, +0, +1), (+1, +0, -1), ) surf = Quad(top_part, stitch, btm_part, stitch.reverse()) fig = plt.figure() ax = plt.subplot(projection="3d") xp, yp = np.meshgrid(np.linspace(-1, +1, 31), np.linspace(-1, +1, 31)) ax.plot_wireframe(*surf.sample(xp, yp)) ax.set(aspect="equal") plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_domains_004.png :alt: plot domains :srcset: /auto_examples/images/sphx_glr_plot_domains_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 151-152 It is of course possible to take a subdomain of this surface. .. GENERATED FROM PYTHON SOURCE LINES 153-162 .. code-block:: Python # This takes the half along the first dimension. sub_surf = surf.subregion((-0.5, +0.5), (-1, +1)) fig = plt.figure() ax = plt.subplot(projection="3d") ax.plot_wireframe(*sub_surf.sample(xp, yp)) ax.set(aspect="equal") plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_domains_005.png :alt: plot domains :srcset: /auto_examples/images/sphx_glr_plot_domains_005.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.538 seconds) .. _sphx_glr_download_auto_examples_plot_domains.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_domains.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_domains.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_domains.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_