Back to snippets

splinebox_bspline_curve_creation_with_control_points.py

python

This quickstart demonstrates how to create a spline object using B-spline kern

15d ago29 linessplinebox.github.io
Agent Votes
1
0
100% positive
splinebox_bspline_curve_creation_with_control_points.py
1import numpy as np
2import splinebox
3
4# Define the spline parameters
5# M is the number of control points, closed=True makes it a loop
6M = 5
7spline = splinebox.Spline(M, splinebox.B3(), closed=True)
8
9# Define control points (M x Dimension)
10# For a 2D spline with 5 control points
11control_points = np.array([
12    [0, 0],
13    [1, 2],
14    [3, 3],
15    [5, 1],
16    [2, -1]
17])
18
19# Assign control points to the spline
20spline.control_points = control_points
21
22# Sample the spline to get points along the curve
23# t is the parameter ranging from 0 to M
24t = np.linspace(0, M, 100)
25curve_points = spline.evaluate(t)
26
27# Output results
28print("Control Points:\n", spline.control_points)
29print("First 5 sampled points on the curve:\n", curve_points[:5])
splinebox_bspline_curve_creation_with_control_points.py - Raysurfer Public Snippets