# Curve & Surface Fitting¶

`geomdl` includes 2 fitting methods for curves and surfaces: approximation and interpolation. Please refer to the Curve and Surface Fitting page for more details on the curve and surface fitting API.

The following sections explain 2-dimensional curve fitting using the included fitting methods. `geomdl` also supports 3-dimensional curve and surface fitting (not shown here). Please refer to the Examples Repository for more examples on curve and surface fitting.

## Interpolation¶

The following code snippet and the figure illustrate interpolation for a 2-dimensional curve:

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14``` ```from geomdl import fitting from geomdl.visualization import VisMPL as vis # The NURBS Book Ex9.1 points = ((0, 0), (3, 4), (-1, 4), (-4, 0), (-4, -3)) degree = 3 # cubic curve # Do global curve interpolation curve = fitting.interpolate_curve(points, degree) # Plot the interpolated curve curve.delta = 0.01 curve.vis = vis.VisCurve2D() curve.render() ```

The following figure displays the input data (sample) points in red and the evaluated curve after interpolation in blue:

## Approximation¶

The following code snippet and the figure illustrate approximation method for a 2-dimensional curve:

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14``` ```from geomdl import fitting from geomdl.visualization import VisMPL as vis # The NURBS Book Ex9.1 points = ((0, 0), (3, 4), (-1, 4), (-4, 0), (-4, -3)) degree = 3 # cubic curve # Do global curve approximation curve = fitting.approximate_curve(points, degree) # Plot the interpolated curve curve.delta = 0.01 curve.vis = vis.VisCurve2D() curve.render() ```

The following figure displays the input data (sample) points in red and the evaluated curve after approximation in blue:

Please note that a spline geometry with a constant set of evaluated points may be represented with an infinite set of control points. The number and positions of the control points depend on the application and the method used to generate the control points.