====== Cubic and bicubic spline interpolation in Python ====== This page contains the source codes associated to the [[https://hal.archives-ouvertes.fr/hal-03017566v2|HAL technical note]] for setting up and plotting cubic splines and bicubic parametric surfaces with various end conditions. Download pdf and Python 3.8 files **Technical note: ** * [[https://hal.archives-ouvertes.fr/hal-03017566v2/document|pdf file (HAL)]] **Cubic splines: ** * {{.:cubic_spline_free_end.py | free end condition}} * {{.:cubic_spline_imposed_tangent_direction.py | imposed tangent direction}} * {{.:cubic_spline_end-to-end_tangent_continuity.py | end-to-end tangent continuity}} * {{.:cubic_spline_not-a-knot.py | not-a-knot end condition}} **Bicubic parametric surfaces: ** * {{.:bicubic_parametric_surface_free_end.py | free end condition}} * {{.:bicubic_parametric_cylinder.py | cylindrical closed surface}} * {{.:bicubic_parametric_sphere.py | spherical closed surface}} * {{.:bicubic_parametric_surface_not-a-knot.py | not-a-knot end condition}} \\ \\ ===== Abstract ===== Cubic and bicubic spline interpolations are widely used in a variety of domains. Nonetheless, there are limited resources available to help students or professionals who wish to implement these tools within a computer program. Be it for visualization purposes or for use within sophisticated algorithms, building a 2D or a 3D spline may not be a straightforward process. In this context, the present technical note provides a brief theoretical description of both splines and bicubic splines but also focuses on the practical implementation of both concepts with an emphasis on the various types of boundary conditions that may be used. In particular, different configurations featuring free end conditions, not-a-knot end conditions or particular tangent orientations to build both open and closed parametric curves and surfaces are detailed. Several source codes—written in Python 3.8—are provided with the intent to facilitate the reproduction of presented results. Proceed to the bottom of the page for an overview of practical examples. \\ \\ ===== 2D cubic spline ===== ==== free end condition ==== Python source code: {{.:cubic_spline_free_end.py | free end condition}}
{{ .:2d_free_end.png?nolink&500 }} cubic spline interpolated on a set of fit knots with free end conditions
==== imposed tangent direction ==== Python source code: {{.:cubic_spline_imposed_tangent_direction.py | imposed tangent direction}}
{{ .:2d_tangent.png?nolink&500 }} cubic spline interpolated on a set of fit knots with imposed tangent directions at ends
==== end-to-end tangent continuity ==== Python source code: {{.:cubic_spline_end-to-end_tangent_continuity.py | end-to-end tangent continuity}}
{{ .:2d_end-to-end.png?nolink&500 }} cubic spline interpolated on a set of fit knots with end-to-end tangent continuity
==== not-a-knot end condition ==== Python source code: {{.:cubic_spline_not-a-knot.py | not-a-knot end condition}}
{{ .:2d_not-a-knot.png?nolink&500 }} cubic spline interpolated on a set of fit knots with not-a-knot end conditions
\\ \\ ===== 3D bicubic parametric surface ===== ==== free end condition ==== Python source code: {{.:bicubic_parametric_surface_free_end.py | free end condition}}
{{ .:3d_free_end.png?nolink&600 }} bicubic parametric surface interpolated on a set of fit knots with free end conditions
==== cylindrical closed surface ==== Python source code: {{.:bicubic_parametric_cylinder.py | cylindrical closed surface}}
{{ .:3d_cylinder.png?nolink&600 }} closed bicubic parametric surface interpolated on a randomized cylindrical set of fit knots
==== spherical closed surface ==== Python source code: {{.:bicubic_parametric_sphere.py | spherical closed surface}}
{{ .:3d_sphere.png?nolink&500 }} fully closed bicubic parametric surface interpolated on a randomized spherical set of fit knots
==== not-a-knot end condition ==== Python source code: {{.:bicubic_parametric_surface_not-a-knot.py | not-a-knot end condition}}
{{ .:3d_free_end.png?nolink&600 }} bicubic parametric surface interpolated on a set of fit knots with not-a-knot end conditions