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.1.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.1-cp313-cp313-win_amd64.whl (357.3 kB view details)

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13Windows x86

splipy-1.9.1-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.1-cp313-cp313-macosx_11_0_arm64.whl (360.1 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12Windows x86

splipy-1.9.1-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.1-cp312-cp312-macosx_11_0_arm64.whl (361.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11Windows x86

splipy-1.9.1-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.1-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.1.tar.gz.

File metadata

  • Download URL: splipy-1.9.1.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.1.tar.gz
Algorithm Hash digest
SHA256 9ba44a9fe2b5efd5ab92f9a2aea1fe06477e35fd814f2fe700aeb70ddffa83b4
MD5 e9be7e8ca7c08ca5afca3e284431f368
BLAKE2b-256 2b59e9da115393713a56abcea559d07f9d2f913725fdb62288720fe31096cba5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: splipy-1.9.1-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.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 28fe52b47d533257fa265079ae960c6db6ca2a7c9e19b8c174554d25b91b8aa5
MD5 939c7d047feae3738492638ca931314f
BLAKE2b-256 f324e969201714d43f1040dc2ea4e1af450f5f1047ad544275d13d2fc0aadca2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: splipy-1.9.1-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.1-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 261d7377e27496c8d83e75bb9ef67298844e00dfa1712085103539c6b785bd59
MD5 eda465a343409e4ecdfe2feeb677ecab
BLAKE2b-256 92f72fe2fca442fd661e61bfd8f39fc7d0c1496ffb0be1739898075458c88b9b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for splipy-1.9.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 76a02a1dd78be1c0bc93d4c48f004c337e3f2a4203919163dcca1f2fe8be4cfa
MD5 ed8e91184e7514371b87567eca414b2e
BLAKE2b-256 3355ecc054c66d9c46a3924ca5fd49e5f3801d6d55e6ca494493db23847c4656

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for splipy-1.9.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c72cddf88b468f0dc32194e78132a6b35e97d336f9b0b3479849d865edc4da3e
MD5 230e5c6261a299d501b0ef1e3c87562e
BLAKE2b-256 cee61e79cc69f21ce3063dae0b7746b8d902b1a3726046c3a3aedcc3cd364796

See more details on using hashes here.

File details

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

File metadata

  • Download URL: splipy-1.9.1-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.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6e35b1e6a78be39a803c3d1a4f01b5f97f6a1af97d167ce75eb86eb7ff640985
MD5 c9c5fdc4f13d5f39c1d440059728f4ec
BLAKE2b-256 3eb7e279ebf1f3719489db7606113e07116d4b83fb18cb1a72e6581cc4c6d1fa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: splipy-1.9.1-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.1-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 65cdd89337c5aae93569fdd2cc93712371707c4df0934fd5488cb34c670da17b
MD5 364d9d2bfe4e1cd5588ba9827fba69e2
BLAKE2b-256 27ca763c997cc05c03156323ca1a9c92271612a9eb562b31261c193470f8f078

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for splipy-1.9.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4b77f804c72b184544bd401bb6cd56178f510fe5a57a9fc2d4229179b86ac4d6
MD5 075cd16a028a1b5a751cc1f97b95badb
BLAKE2b-256 651614f0380384a5d88d8f36e64a2a47bb4f71459a8b8cd306a1f1bf6ec72914

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for splipy-1.9.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d7bf0f2d7c5594eef6a3d57f6491566ce48cb5da2138bbb1711bc20d441baa1a
MD5 0b8723ce2e8aeba2c500d0bcd228062f
BLAKE2b-256 347e869a9ab63adfa288cb5c08a300d4b9cdcbc847a22e67c0e921222cd82412

See more details on using hashes here.

File details

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

File metadata

  • Download URL: splipy-1.9.1-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.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 764dc815955f3c2fa78561ab625f79ba86154e275f735706a3a42321b1f6efed
MD5 ba0db63a17b71e703fcd5037a780832a
BLAKE2b-256 1adb235142bb6e4d0f6fd9a432abe69bd0c33bdbc6c286f0e931ab2fcc624a9f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: splipy-1.9.1-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.1-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 a3ece4a64da4f869aae0423a2943200de2932e5e56be493ae5d39f3e8710604b
MD5 ad214c4af498503317a587850fbcaaac
BLAKE2b-256 3c324803c88e82787712c8a5e1ee1c7bcec22ebab6eac292a5136dbf17277ab0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for splipy-1.9.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e2aed480e00f417c6b5b6adc473f9f20c13f48afb628eb4d3bd0f9cdca2ee5be
MD5 f72e74e44772fe6c6efe675963976436
BLAKE2b-256 fea9a8be3bf78f7b49325e134e57b1d3a0494d20e4d839e012bcc3aee2c14a4c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for splipy-1.9.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7872384f42def0dfda5857019b5460fb80903ac4b9999c2bbfc11e07c91a888a
MD5 b1f9ce38fc3e9af32cac4cf66643fce2
BLAKE2b-256 7c01fbab60574081d9b16f8640a43bc2ea7a7b0095999313d3c0e590649e476f

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