top of page

Create spline through points

  • Peter Mortier
  • Jan 19
  • 1 min read

Updated: 6 days ago

Discover how to create a spline through points with a few lines of Python code.


In this example, we start by defining an array containing five distinct points. These points serve as the foundation for our spline. Next, we utilize the spline function, which is designed to generate a mesh composed of line elements. Specifically, we will create 20 line elements between each pair of consecutive points (n = 20), ensuring a smooth transition between them. In this case, we choose to generate a closed spline by setting the 'closed' argument to true. This feature allows the spline to seamlessly connect back to the starting point, creating a smooth loop.


As a final step, we create a circle and sweep it along the spline path. This visual representation highlights the smoothness of the spline.


from hellotriangle import shapes

# input points
points = [[0.0, 0.0, 0.0],
          [1.0, 3.0, 1.0],
          [2.0, 1.0, 0.0],
          [2.5, 0.0, -1.0],
          [1.5, -1.0, 0.0]]

# generate spline
spl = shapes.spline(points, n = 20, closed = True)

# sweep circle profile along path
cir = shapes.circle(n = 10).scale([0.1, 0.1, 0.1])
quad = cir.sweep(spl, normal = [0.0, 0.0, 1.0])

# draw
draw(quad, color = "#D62246", show_edges = True)

Create spline through points
Figure: Closed spline generated through 5 input points (argument closed = True)

Subscribe to our newsletter

Join our email list and get updates about HelloTriangle. Unsubscribe anytime.

Thanks for submitting!

© 2024 by HelloTriangle

  • LinkedIn
bottom of page