shapes.spline#
- shapes.spline(points, div=10, closed=False, equidistant=True)#
Create a cubic Bezier spline through given points.
The spline is constructed as a smooth curve interpolating the specified control points. The resulting curve is discretized into a polyline mesh with line elements.
Parameters#
- points: coords_like
An (npts,3) shaped array with the coordinates of the control points of the spline, or any other data accepted by the
Coordsinitialization.- divint or list of int, optional
Subdivision specification. The behavior depends on the type:
int, with equidistant=True: total number of segments along the entire curve. The control points may not coincide with mesh vertices.
int, with equidistant=False: number of subdivisions per segment between two consecutive control points. Control points are guaranteed to be vertices.
list of int: explicit number of subdivisions per segment between consecutive control points. Length of list must equal the number of spline segments (
npts-1if open,nptsif closed).
- closedbool, optional
If True, the spline is closed by connecting the last control point back to the first, forming a closed loop. Default is False.
- equidistantbool, optional
Only relevant when
divis an integer. If True,divis interpreted as the total number of equidistant segments. If False, it is interpreted as the number of subdivisions per segment. Default is True.
Returns#
- Mesh
A line mesh (
eltype="line2") representing the discretized spline.
Examples#
Global equidistant mode (20 segments in total):
>>> pts = [[0.0, 0.0], [3.0, 0.0], [7.0, 4.0], [7.0, 8.0]] >>> M1 = spline(pts, div=20, equidistant=True) >>> print(M1.n_elems()) 20 >>> np.isclose(M1.lengths().min(), 0.646, rtol=1e-3, atol=1e-6) True >>> np.isclose(M1.lengths().max(), 0.646, rtol=1e-3, atol=1e-6) True
Uniform per-segment mode (3 subdivisions between each pair of control points):
>>> M2 = spline(pts, div=3, equidistant=False) >>> print(M2.n_elems()) 9
Subdivision per-segment:
>>> M3 = spline(pts, div=[4, 3, 5, 5], closed=True) >>> print(M3.n_elems()) 17