Skip to content

Commit

Permalink
Add basis functions graphs when inserting nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-adir committed Sep 9, 2023
1 parent a4b5036 commit da87bae
Show file tree
Hide file tree
Showing 12 changed files with 24,337 additions and 36 deletions.
1,685 changes: 1,685 additions & 0 deletions docs/source/img/basis-functions/insertion025_p3step0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,054 changes: 2,054 additions & 0 deletions docs/source/img/basis-functions/insertion025_p3step1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,436 changes: 2,436 additions & 0 deletions docs/source/img/basis-functions/insertion025_p3step2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,766 changes: 2,766 additions & 0 deletions docs/source/img/basis-functions/insertion025_p3step3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3,094 changes: 3,094 additions & 0 deletions docs/source/img/basis-functions/insertion025_p3step4.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,685 changes: 1,685 additions & 0 deletions docs/source/img/basis-functions/insertion_p3step0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,059 changes: 2,059 additions & 0 deletions docs/source/img/basis-functions/insertion_p3step1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,447 changes: 2,447 additions & 0 deletions docs/source/img/basis-functions/insertion_p3step2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,782 changes: 2,782 additions & 0 deletions docs/source/img/basis-functions/insertion_p3step3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3,109 changes: 3,109 additions & 0 deletions docs/source/img/basis-functions/insertion_p3step4.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
224 changes: 203 additions & 21 deletions docs/source/rst/basisfunction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Although above the function :math:`B_{i,p}(u)` is described only by :math:`p`, b
.. image:: ../img/basis-functions/bezier-basisfunction-p1.svg
:width: 100 %
:alt: Basis functions for bezier of degree 1
:alt: Uniform basis functions for bezier of degree 1
:align: center

.. dropdown:: Basis functions for degree :math:`p=2`
Expand Down Expand Up @@ -189,55 +189,55 @@ Use example



.. dropdown:: Basis functions for degree :math:`p=0` and :math:`\text{npts}=6`
.. dropdown:: Uniform basis functions for degree :math:`p=0` and :math:`\text{npts}=6`

.. math::
\mathbf{U} = \left(0, \ \dfrac{1}{6}, \ \dfrac{2}{6}, \ \dfrac{3}{6}, \ \dfrac{4}{6}, \ \dfrac{5}{6}, \ 1\right)
.. image:: ../img/basis-functions/splines-basisfunction-p0n6.svg
:width: 100 %
:alt: Basis functions for splines of degree 0
:alt: Uniform basis functions for splines of degree 0
:align: center

.. dropdown:: Basis functions for degree :math:`p=1` and :math:`\text{npts}=6`
.. dropdown:: Uniform basis functions for degree :math:`p=1` and :math:`\text{npts}=6`

.. math::
\mathbf{U} = \left(0, \ 0, \ \dfrac{1}{5}, \ \dfrac{2}{5}, \ \dfrac{3}{5}, \ \dfrac{4}{5}\ 1, \ 1 \right)
.. image:: ../img/basis-functions/splines-basisfunction-p1n6.svg
:width: 100 %
:alt: Basis functions for splines of degree 1
:alt: Uniform basis functions for splines of degree 1
:align: center

.. dropdown:: Basis functions for degree :math:`p=2` and :math:`\text{npts}=6`
.. dropdown:: Uniform basis functions for degree :math:`p=2` and :math:`\text{npts}=6`

.. math::
\mathbf{U} = \left(0, \ 0, \ 0, \ \dfrac{1}{4}, \ \dfrac{2}{4}, \ \dfrac{3}{4}, \ 1, \ 1, \ 1 \right)
.. image:: ../img/basis-functions/splines-basisfunction-p2n6.svg
:width: 100 %
:alt: Basis functions for splines of degree 2
:alt: Uniform basis functions for splines of degree 2
:align: center

.. dropdown:: Basis functions for degree :math:`p=3` and :math:`\text{npts}=6`
.. dropdown:: Uniform basis functions for degree :math:`p=3` and :math:`\text{npts}=6`

.. math::
\mathbf{U} = \left(0, \ 0, \ 0, \ 0, \ \dfrac{1}{3}, \ \dfrac{2}{3}, \ 1, \ 1, \ 1, \ 1 \right)
.. image:: ../img/basis-functions/splines-basisfunction-p3n6.svg
:width: 100 %
:alt: Basis functions for splines of degree 3
:alt: Uniform basis functions for splines of degree 3
:align: center


.. dropdown:: Basis functions for degree :math:`p=4` and :math:`\text{npts}=6`
.. dropdown:: Uniform basis functions for degree :math:`p=4` and :math:`\text{npts}=6`

.. math::
\mathbf{U} = \left(0, \ 0, \ 0, \ 0, \ 0, \ \dfrac{1}{2}, \ 1, \ 1, \ 1, \ 1, \ 1 \right)
.. image:: ../img/basis-functions/splines-basisfunction-p4n6.svg
:width: 100 %
:alt: Basis functions for splines of degree 4
:alt: Uniform basis functions for splines of degree 4
:align: center

.. dropdown:: Code to generate all the spline basis functions
Expand Down Expand Up @@ -318,7 +318,7 @@ Use example



.. dropdown:: Basis functions for degree :math:`p=0` and :math:`\text{npts}=6`
.. dropdown:: Uniform basis functions for degree :math:`p=0` and :math:`\text{npts}=6`

.. math::
\mathbf{U} = \left(0, \ \dfrac{1}{6}, \ \dfrac{2}{6}, \ \dfrac{3}{6}, \ \dfrac{4}{6}, \ \dfrac{5}{6}, \ 1\right)
Expand All @@ -328,10 +328,10 @@ Use example
.. image:: ../img/basis-functions/rational-basisfunction-p0n6.svg
:width: 100 %
:alt: Basis functions for rational splines of degree 0
:alt: Uniform basis functions for rational splines of degree 0
:align: center

.. dropdown:: Basis functions for degree :math:`p=1` and :math:`\text{npts}=6`
.. dropdown:: Uniform basis functions for degree :math:`p=1` and :math:`\text{npts}=6`

.. math::
\mathbf{U} = \left(0, \ 0, \ \dfrac{1}{5}, \ \dfrac{2}{5}, \ \dfrac{3}{5}, \ \dfrac{4}{5}\ 1, \ 1 \right)
Expand All @@ -341,10 +341,10 @@ Use example
.. image:: ../img/basis-functions/rational-basisfunction-p1n6.svg
:width: 100 %
:alt: Basis functions for rational splines of degree 1
:alt: Uniform basis functions for rational splines of degree 1
:align: center

.. dropdown:: Basis functions for degree :math:`p=2` and :math:`\text{npts}=6`
.. dropdown:: Uniform basis functions for degree :math:`p=2` and :math:`\text{npts}=6`

.. math::
\mathbf{U} = \left(0, \ 0, \ 0, \ \dfrac{1}{4}, \ \dfrac{2}{4}, \ \dfrac{3}{4}, \ 1, \ 1, \ 1 \right)
Expand All @@ -354,10 +354,10 @@ Use example
.. image:: ../img/basis-functions/rational-basisfunction-p2n6.svg
:width: 100 %
:alt: Basis functions for splines of degree 2
:alt: Uniform basis functions for splines of degree 2
:align: center

.. dropdown:: Basis functions for degree :math:`p=3` and :math:`\text{npts}=6`
.. dropdown:: Uniform basis functions for degree :math:`p=3` and :math:`\text{npts}=6`

.. math::
\mathbf{U} = \left(0, \ 0, \ 0, \ 0, \ \dfrac{1}{3}, \ \dfrac{2}{3}, \ 1, \ 1, \ 1, \ 1 \right)
Expand All @@ -367,11 +367,11 @@ Use example
.. image:: ../img/basis-functions/rational-basisfunction-p3n6.svg
:width: 100 %
:alt: Basis functions for rational splines of degree 3
:alt: Uniform basis functions for rational splines of degree 3
:align: center


.. dropdown:: Basis functions for degree :math:`p=4` and :math:`\text{npts}=6`
.. dropdown:: Uniform basis functions for degree :math:`p=4` and :math:`\text{npts}=6`

.. math::
\mathbf{U} = \left(0, \ 0, \ 0, \ 0, \ 0, \ \dfrac{1}{2}, \ 1, \ 1, \ 1, \ 1, \ 1 \right)
Expand All @@ -381,7 +381,7 @@ Use example
.. image:: ../img/basis-functions/rational-basisfunction-p4n6.svg
:width: 100 %
:alt: Basis functions for rational splines of degree 4
:alt: Uniform basis functions for rational splines of degree 4
:align: center

.. dropdown:: Code to generate all the rational spline basis functions
Expand Down Expand Up @@ -419,3 +419,185 @@ Use example
ax.grid()
fig.tight_layout()
plt.savefig("rational-basisfunction-p%dn%d.svg"%(degree, nptsmax))
-----------------------------------------------------------------------

-----------------------------
Inserting knots in knotvector
-----------------------------

We get an specific case and start inserting knots at center to see what happens with the basis functions

We start with the bezier of degree 3

.. math::
\mathbf{U} = \left(0, \ 0, \ 0, \ 0, \ 1, \ 1, \ 1, \ 1 \right)
.. image:: ../img/basis-functions/insertion_p3step0.svg
:width: 100 %
:alt: Initial basis functions of test
:align: center


.. math::
\mathbf{U} = \left(0, \ 0, \ 0, \ 0, \ 0.5, \ 1, \ 1, \ 1, \ 1 \right)
.. image:: ../img/basis-functions/insertion_p3step1.svg
:width: 100 %
:alt: Initial basis functions of test
:align: center


.. math::
\mathbf{U} = \left(0, \ 0, \ 0, \ 0, \ 0.5,\ 0.5, \ 1, \ 1, \ 1, \ 1 \right)
.. image:: ../img/basis-functions/insertion_p3step2.svg
:width: 100 %
:alt: Initial basis functions of test
:align: center


.. math::
\mathbf{U} = \left(0, \ 0, \ 0, \ 0, \ 0.5,\ 0.5, \ 0.5, \ 1, \ 1, \ 1, \ 1 \right)
.. image:: ../img/basis-functions/insertion_p3step3.svg
:width: 100 %
:alt: Initial basis functions of test
:align: center

.. math::
\mathbf{U} = \left(0, \ 0, \ 0, \ 0, \ 0.5, \ 0.5,\ 0.5, \ 0.5, \ 1, \ 1, \ 1, \ 1 \right)
.. image:: ../img/basis-functions/insertion_p3step4.svg
:width: 100 %
:alt: Initial basis functions of test
:align: center


.. dropdown:: Code to plot


.. code-block:: python
import numpy as np
from matplotlib import pyplot as plt
from compmec.nurbs import GeneratorKnotVector, Function
prop_cycle = plt.rcParams['axes.prop_cycle']
colors = prop_cycle.by_key()['color']
uplot = np.linspace(0, 1, 1029)
knotvector = GeneratorKnotVector.bezier(3)
knots_insert = [0.5, 0.5, 0.5, 0.5, 0.75]
for k, knot in enumerate(knots_insert):
nfigsx = knotvector.npts
sizex = nfigsx*4
sizey = 3
fig, axs = plt.subplots(1, nfigsx, figsize=(sizex,sizey))
function = Function(knotvector)
allvalues = function(uplot)
for i, values in enumerate(allvalues):
label = r"$N_{%d,%d}$"%(i,knotvector.degree)
color = colors[i]
ax = axs[i]
ax.plot(uplot, values, label=label, linewidth=3,color=color)
ax.set_xlim(-0.1, 1.1)
ax.set_ylim(-0.1, 1.1)
ax.legend()
ax.grid()
fig.tight_layout()
plt.savefig("insertion_p%dstep%d.svg"%(knotvector.degree, k))
knotvector.insert([knot])
-----------------------------------------------------------------------

-------------------
Non uniform splines
-------------------

This section shows the basis function when the knotvector is not uniform.

We do it by inserting the knot :math:`0.25` many times by starting with a bezier curve of degree 3



.. math::
\mathbf{U} = \left(0, \ 0, \ 0, \ 0, \ 1, \ 1, \ 1, \ 1 \right)
.. image:: ../img/basis-functions/insertion025_p3step0.svg
:width: 100 %
:alt: Initial basis functions of test
:align: center


.. math::
\mathbf{U} = \left(0, \ 0, \ 0, \ 0, \ 0.25, \ 1, \ 1, \ 1, \ 1 \right)
.. image:: ../img/basis-functions/insertion025_p3step1.svg
:width: 100 %
:alt: Initial basis functions of test
:align: center


.. math::
\mathbf{U} = \left(0, \ 0, \ 0, \ 0, \ 0.25,\ 0.25, \ 1, \ 1, \ 1, \ 1 \right)
.. image:: ../img/basis-functions/insertion025_p3step2.svg
:width: 100 %
:alt: Initial basis functions of test
:align: center


.. math::
\mathbf{U} = \left(0, \ 0, \ 0, \ 0, \ 0.25,\ 0.25, \ 0.25, \ 1, \ 1, \ 1, \ 1 \right)
.. image:: ../img/basis-functions/insertion025_p3step3.svg
:width: 100 %
:alt: Initial basis functions of test
:align: center

.. math::
\mathbf{U} = \left(0, \ 0, \ 0, \ 0, \ 0.25, \ 0.25,\ 0.25, \ 0.25, \ 1, \ 1, \ 1, \ 1 \right)
.. image:: ../img/basis-functions/insertion025_p3step4.svg
:width: 100 %
:alt: Initial basis functions of test
:align: center


.. dropdown:: Code to plot


.. code-block:: python
import numpy as np
from matplotlib import pyplot as plt
from compmec.nurbs import GeneratorKnotVector, Function
prop_cycle = plt.rcParams['axes.prop_cycle']
colors = prop_cycle.by_key()['color']
uplot = np.linspace(0, 1, 1029)
knotvector = GeneratorKnotVector.bezier(3)
knots_insert = [0.25, 0.25, 0.25, 0.25, 0.75]
for k, knot in enumerate(knots_insert):
nfigsx = knotvector.npts
sizex = nfigsx*4
sizey = 3
fig, axs = plt.subplots(1, nfigsx, figsize=(sizex,sizey))
function = Function(knotvector)
allvalues = function(uplot)
for i, values in enumerate(allvalues):
label = r"$N_{%d,%d}$"%(i,knotvector.degree)
color = colors[i]
ax = axs[i]
ax.plot(uplot, values, label=label, linewidth=3,color=color)
ax.set_xlim(-0.1, 1.1)
ax.set_ylim(-0.1, 1.1)
ax.legend()
ax.grid()
fig.tight_layout()
plt.savefig("insertion025_p%dstep%d.svg"%(knotvector.degree, k))
knotvector.insert([knot])
Loading

0 comments on commit da87bae

Please sign in to comment.