Skip to main content

Spline modelling library for Python

Project description

Splipy Logo SpliPy

This repository contains the SpliPy packages. SpliPy is a pure python library for the creation, evaluation and manipulation of B-spline and NURBS geometries. It supports n-variate splines of any dimension, but emphasis is made on the use of curves, surfaces and volumes. The library is designed primarily for analysis use, and therefore allows fine-grained control over many aspects which is not possible to achieve with conventional CAD tools.

Features

SpliPy allows for the generation of parametric curves, surfaces and volumes in the form of non-uniform rational B-splines (NURBS). It supports traditional curve- and surface-fitting methods such as (but not limited to)

Curve fitting

  • Bezier curves
  • Hermite Interpolation
  • Cubic Curve Interpolation
  • B-spline Interpolation
  • Least Square Fit

Surface operations

  • Sweep
  • Revolve
  • Loft
  • Edge_Curves (interior from four edges)
  • Extrude
  • Structured Point Cloud Interpolation
  • Least Square Fit

Revolve Revolve

Sweep Sweep

Loft Loft

Volume operations

  • Revolve
  • Extrude
  • Loft
  • Structured Point Cloud Interpolation
  • Least Square Fit

In addition to these basic building blocks, it also supports a number of primitive shapes such as (but not limited to)

Primitive shapes

  • Cube
  • Circle
  • Disc
  • Cylinder
  • Torus
  • Teapot

Examples

Derivatives of spline curves

  from splipy import *
  import numpy as np

  n = 250                                  # number of evaluation points
  c = curve_factory.circle()               # create the NURBS circle (r=1)
  t = np.linspace(c.start(0), c.end(0), n) # parametric evaluation points
  x = c(t)                                 # physical (x,y)-coordinates, size (n,2)
  v = c.derivative(t, 1)                   # velocity at all points
  a = c.derivative(t, 2)                   # acceleration at all points

Missing circle animation

Curve fitting

Lissajous curves are a family of parametric curves of the type

x = A sin(at+d)
y = B sin(bt)

More info: https://en.wikipedia.org/wiki/Lissajous_curve. Stripping the animation parts of the code, one can generate these curves in the following way

from splipy import *
import numpy as np
from fractions import gcd

def lissajous(a, b, d):
  # request a,b integers, so we have closed, periodic curves
  n = np.gcd(a,b)
  N = (a/n) * (b/n) # number of periods before looping

  # compute a set of interpolation points
  numb_pts = max(3*N, 100) # using 3N interpolation points is decent enough
  t = np.linspace(0,2*np.pi/n, numb_pts)
  x = np.array([np.sin(a*t + d), np.sin(b*t)])

# do a cubic curve interpolation with periodic boundary conditions
my_curve = curve_factory.cubic_curve(x.T, curve_factory.Boundary.PERIODIC)

Missing Lissajous curve animation

Animation of the lissajous curve with a=3, b=4 and d=pi/2

Surface Sweep

This produces the trefoil knot shown above

from splipy import *
from numpy import pi,cos,sin,transpose,array,sqrt

# define a parametric representation of the trefoil knot (to be sampled)
def trefoil(u):
  x = [41*cos(u) - 18*sin(  u) -  83*cos(2*u) - 83*sin(2*u) - 11*cos(3*u) + 27*sin(3*u),
       36*cos(u) + 27*sin(  u) - 113*cos(2*u) + 30*sin(2*u) + 11*cos(3*u) - 27*sin(3*u),
       45*sin(u) - 30*cos(2*u) + 113*sin(2*u) - 11*cos(3*u) + 27*sin(3*u)]
  return transpose(array(x))

knot_curve   = curve_factory.fit(trefoil, 0, 2*pi) # adaptive curve fit of trefoil knot
square_curve = 15 * curve_factory.n_gon(4)         # square cross-section
my_surface   = surface_factory.sweep(crv, square)  # sweep out the surface

Working with the controlpoints

>>> from splipy import *
>>> my_curve = curve_factory.circle(r=3)
>>> print(my_curve[0])
[3. 0. 1.]
>>> print(my_curve[1])
[2.12132034 2.12132034 0.70710678]
>>> for controlpoint in my_curve:
...     print(controlpoint)
[3. 0. 1.]
[2.12132034 2.12132034 0.70710678]
[0. 3. 1.]
[-2.12132034  2.12132034  0.70710678]
[-3.  0.  1.]
[-2.12132034 -2.12132034  0.70710678]
[ 0. -3.  1.]
[ 2.12132034 -2.12132034  0.70710678]

Creating STL files

STL files are used extensively for 3D representation and is one of the only supported formats for 3D printing.

from splipy.io import STL
from splipy import surface_factory

# create a NURBS torus
my_torus = surface_factory.torus(minor_r=1, major_r=4)

# STL files are tessellated linear triangles. View with i.e. meshlab
with STL('torus.stl') as my_file:
    my_file.write(my_torus, n=(50, 150)) # specify resolution of 50x150 evaluation pts

Torus tessellation as viewed in Meshlab Torus

Citations

If you use Splipy in your work, please consider citing K. A. Johannessen and E. Fonn 2020 J. Phys.: Conf. Ser. 1669 012032.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

splipy-1.9.2.tar.gz (107.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

splipy-1.9.2-cp313-cp313-win_amd64.whl (357.3 kB view details)

Uploaded CPython 3.13Windows x86-64

splipy-1.9.2-cp313-cp313-win32.whl (345.5 kB view details)

Uploaded CPython 3.13Windows x86

splipy-1.9.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (768.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

splipy-1.9.2-cp313-cp313-macosx_11_0_arm64.whl (360.1 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

splipy-1.9.2-cp312-cp312-win_amd64.whl (357.5 kB view details)

Uploaded CPython 3.12Windows x86-64

splipy-1.9.2-cp312-cp312-win32.whl (345.7 kB view details)

Uploaded CPython 3.12Windows x86

splipy-1.9.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (771.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

splipy-1.9.2-cp312-cp312-macosx_11_0_arm64.whl (361.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

splipy-1.9.2-cp311-cp311-win_amd64.whl (357.0 kB view details)

Uploaded CPython 3.11Windows x86-64

splipy-1.9.2-cp311-cp311-win32.whl (345.2 kB view details)

Uploaded CPython 3.11Windows x86

splipy-1.9.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (781.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

splipy-1.9.2-cp311-cp311-macosx_11_0_arm64.whl (360.0 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file splipy-1.9.2.tar.gz.

File metadata

  • Download URL: splipy-1.9.2.tar.gz
  • Upload date:
  • Size: 107.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for splipy-1.9.2.tar.gz
Algorithm Hash digest
SHA256 9b29923dbfd944405885b5488e60ca146e22f6d5062fc7cbe8923a8a6ac44f21
MD5 896f3ee14a55f98e2475587ef3589c05
BLAKE2b-256 0d924571ac35d9b3d49b07034b5abefcbfc66e9df9bb28ec3b0684b2419a99dd

See more details on using hashes here.

File details

Details for the file splipy-1.9.2-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: splipy-1.9.2-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 357.3 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for splipy-1.9.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 484be6b166dc0bec7227163743cbf9cf67dd04c1d26dc25da11bc530a5f6b259
MD5 e17f17a663818fafe41b6a1e7bfc1008
BLAKE2b-256 657097f42c8c37a8f7254f9fec173dcd8792c4c6d03c024116d2b5cbec7c6c75

See more details on using hashes here.

File details

Details for the file splipy-1.9.2-cp313-cp313-win32.whl.

File metadata

  • Download URL: splipy-1.9.2-cp313-cp313-win32.whl
  • Upload date:
  • Size: 345.5 kB
  • Tags: CPython 3.13, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for splipy-1.9.2-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 4f072e4bcfb58cf9c9e27dbe9b239ac8fd8e6d95ca29d05e114b246f00d34329
MD5 c9145034989fb91e59a7e3822fad7fd9
BLAKE2b-256 942aa6a3688526a3c9728b320b81d9c7eaeb5db69cc47d7f1ab0f5cfee5f703d

See more details on using hashes here.

File details

Details for the file splipy-1.9.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for splipy-1.9.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f073191d6102edd6e133bf0d650932fc15a46341fd95cb3133fb367b932e59db
MD5 aad90e8bd86c5a1de17d165deb2cafaf
BLAKE2b-256 b856c8c53ddde07157e26501b9eb7aa075081b63e002e5e2f8b73c072746d1ad

See more details on using hashes here.

File details

Details for the file splipy-1.9.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for splipy-1.9.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 11171b05c23665735637ceab1b55d4f8cb073a175bba38b4243e603bc97192b3
MD5 17594af255e0d6f3acf33fa39e0a4d2d
BLAKE2b-256 ea67b76dfed4b141089f69f4af4121e666b6f010a611d99f63ae62d0b548869c

See more details on using hashes here.

File details

Details for the file splipy-1.9.2-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: splipy-1.9.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 357.5 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for splipy-1.9.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a59defbfae1d49a69dae2f11dd315b1aa13af305f8a2e563cc383d36f4e1b95e
MD5 83e580611c0df6ef60d05c49fe2a1611
BLAKE2b-256 a44fae76f31dc8782151a16563914a7af6e167c89c3981dbdb99e29b448792d0

See more details on using hashes here.

File details

Details for the file splipy-1.9.2-cp312-cp312-win32.whl.

File metadata

  • Download URL: splipy-1.9.2-cp312-cp312-win32.whl
  • Upload date:
  • Size: 345.7 kB
  • Tags: CPython 3.12, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for splipy-1.9.2-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 e74e273f684e42f789a915766c2d0d4327ad3c577c57969faa711504bae523dc
MD5 13cb2c9b5b4fcfa3664db8a514cd2fa9
BLAKE2b-256 606d48e395b1ed74f5cf475e9a9ff9d5d06c22617f4acf3f9cd3dcca43698d14

See more details on using hashes here.

File details

Details for the file splipy-1.9.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for splipy-1.9.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a2097223b31f278a4f2bd358b3d1ac5a33790787a7ed59b3ceacf9863bdd33a0
MD5 c00e8db9bf030a48a10ebd9a647c1338
BLAKE2b-256 1e81f956379eba2a7961afc6cabb069482b98861319e1f1d8292a2f5ee9ea9af

See more details on using hashes here.

File details

Details for the file splipy-1.9.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for splipy-1.9.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c175707e61730f9eedada680f7fb20148f1321fe7bd1ff5930730838033d0a02
MD5 ae0caa76896889551a32c9bbf35715b2
BLAKE2b-256 e5bf8f3c92a6dd796f59af6ccfcf871f8c1167e6c3aec5947440e2a2aced52a6

See more details on using hashes here.

File details

Details for the file splipy-1.9.2-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: splipy-1.9.2-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 357.0 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for splipy-1.9.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 4bec0aeb5e956e9a0b5dbac5a894e85aca1094eee961d9e3674f5831bba0c7a1
MD5 63eb78d540433ecf2293f7e8df04995d
BLAKE2b-256 0ccad4af92af8acfe1f910a9c29fecfc5b12a739c31b36b3471d3bdb9552cbe3

See more details on using hashes here.

File details

Details for the file splipy-1.9.2-cp311-cp311-win32.whl.

File metadata

  • Download URL: splipy-1.9.2-cp311-cp311-win32.whl
  • Upload date:
  • Size: 345.2 kB
  • Tags: CPython 3.11, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for splipy-1.9.2-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 3e818e797f36363f940e6fc801b8006cd4d8a62e8862d195149d3f613103afb9
MD5 dee1e6683ca2785b910329642e214552
BLAKE2b-256 5ef003addfa3df8f3985c198db405af63a1e43c66057f279b3b373f85e7f7500

See more details on using hashes here.

File details

Details for the file splipy-1.9.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for splipy-1.9.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b63ff2240110a431dd081515f75c6cb02981c8e869273dc89b074d71f77a169e
MD5 1faf3e037c40b70822ab3234b9f3e81b
BLAKE2b-256 2cc9945f954b6938c7061be143ecbd13b14a88b35745e284e846a7e77ce92129

See more details on using hashes here.

File details

Details for the file splipy-1.9.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for splipy-1.9.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 73f62170ff8516f3fe4c64b853693db5ccca9bbd62915f0eb8dde89b895e641b
MD5 973ba58855d9e068763d96d07ba18aa3
BLAKE2b-256 56be18b1162b9d92c4b19cbbd8edbec2cba398edee91dee5a3be7dc8bbecaadc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page