
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/plot_curvature_combs.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_auto_examples_plot_curvature_combs.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_plot_curvature_combs.py:


Curvature combs
---------------

In this example we plot the curvature comb of a 2D spline.
Curvature combs are useful to highlight changes in curvature.

.. GENERATED FROM PYTHON SOURCE LINES 8-36



.. image-sg:: /auto_examples/images/sphx_glr_plot_curvature_combs_001.png
   :alt: plot curvature combs
   :srcset: /auto_examples/images/sphx_glr_plot_curvature_combs_001.png
   :class: sphx-glr-single-img





.. code-block:: Python

    import matplotlib.pyplot as plt
    import numpy as np
    import splinebox

    M = 7
    spline = splinebox.Spline(M=M, basis_function=splinebox.B3(), closed=False)
    spline.knots = np.array([[0, 0], [1, 1], [2.5, 0.5], [3.5, 1.5], [3, 3], [2, 3.5], [1, 2]])

    t = np.linspace(0, M - 1, 1000)

    vals = spline.eval(t)

    curvature = spline.curvature(t)
    normals = spline.normal(t)

    # You can limit the max height of the curvature comb using the factor d.
    max_comb_height = 1
    d = max_comb_height / np.max(np.abs(curvature))

    comb = vals + d * curvature[:, np.newaxis] * normals

    plt.plot(vals[:, 1], vals[:, 0], label="spline")
    plt.plot(comb[:, 1], comb[:, 0], label="Curvature comb", color="lightsteelblue")
    for p in range(0, len(comb), 7):
        plt.plot([vals[p, 1], comb[p, 1]], [vals[p, 0], comb[p, 0]], color="lightsteelblue")
    plt.gca().set_aspect("equal", "box")
    plt.legend()
    plt.show()


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 2.620 seconds)


.. _sphx_glr_download_auto_examples_plot_curvature_combs.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: plot_curvature_combs.ipynb <plot_curvature_combs.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: plot_curvature_combs.py <plot_curvature_combs.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: plot_curvature_combs.zip <plot_curvature_combs.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
