Skip to main content

A comprehensive Python library for generating smooth trajectories and curves with precise control over position, velocity, acceleration, and jerk profiles

Project description

InterpolatePy

Python PyPI Downloads pre-commit ci-test License: MIT

Production-ready trajectory planning and interpolation for robotics, animation, and scientific computing.

InterpolatePy provides 20+ algorithms for smooth trajectory generation with precise control over position, velocity, acceleration, and jerk. From cubic splines and B-curves to quaternion interpolation and S-curve motion profiles — everything you need for professional motion control.

⚡ Fast: Optional C++ backend with pybind11; pure-Python fallback uses vectorized NumPy 🎯 Precise: Research-grade algorithms with C² continuity and bounded derivatives 📊 Visual: Built-in plotting for every algorithm 🔧 Complete: Splines, motion profiles, quaternions, and path planning in one library


Installation

pip install InterpolatePy

Requirements: Python ≥3.11, NumPy ≥2.3, SciPy ≥1.16, Matplotlib ≥3.10.5

Development Installation

This project uses uv for dependency and environment management.

git clone https://github.com/GiorgioMedico/InterpolatePy.git
cd InterpolatePy
uv sync  # creates .venv with the default dev + test groups

To include the docs group as well: uv sync --all-groups.

Quick Start

import numpy as np
import matplotlib.pyplot as plt
from interpolatepy import CubicSpline, DoubleSTrajectory, StateParams, TrajectoryBounds

# Smooth spline through waypoints
t_points = [0.0, 5.0, 10.0, 15.0]
q_points = [0.0, 2.0, -1.0, 3.0]
spline = CubicSpline(t_points, q_points, v0=0.0, vn=0.0)

# Evaluate at any time
position = spline.evaluate(7.5)
velocity = spline.evaluate_velocity(7.5)
acceleration = spline.evaluate_acceleration(7.5)

# Built-in visualization
spline.plot()

# S-curve motion profile (jerk-limited)
state = StateParams(q_0=0.0, q_1=10.0, v_0=0.0, v_1=0.0)
bounds = TrajectoryBounds(v_bound=5.0, a_bound=10.0, j_bound=30.0)
trajectory = DoubleSTrajectory(state, bounds)

print(f"Duration: {trajectory.get_duration():.2f}s")

# Manual plotting (DoubleSTrajectory doesn't have built-in plot method)
t_eval = np.linspace(0, trajectory.get_duration(), 100)
results = [trajectory.evaluate(t) for t in t_eval]
positions = [r[0] for r in results]
velocities = [r[1] for r in results]

plt.figure(figsize=(10, 6))
plt.subplot(2, 1, 1)
plt.plot(t_eval, positions)
plt.ylabel('Position')
plt.title('S-Curve Trajectory')
plt.subplot(2, 1, 2)
plt.plot(t_eval, velocities)
plt.ylabel('Velocity')
plt.xlabel('Time')

plt.show()

Algorithm Overview

Category Algorithms Key Features Use Cases
🔵 Splines Cubic, B-Spline, Smoothing C² continuity, noise-robust Waypoint interpolation, curve fitting
⚡ Motion Profiles S-curves, Trapezoidal, Polynomial Bounded derivatives, time-optimal Industrial automation, robotics
🔄 Quaternions SLERP, SQUAD, Splines Smooth rotations, no gimbal lock 3D orientation control, animation
🎯 Path Planning Linear, Circular, Frenet frames Geometric primitives, tool orientation Path following, machining

📚 Complete Algorithms Reference →
Detailed technical documentation, mathematical foundations, and implementation details for all 22 algorithms

Complete Algorithm List

Spline Interpolation

  • CubicSpline – Natural cubic splines with boundary conditions
  • CubicSmoothingSpline – Noise-robust splines with smoothing parameter
  • CubicSplineWithAcceleration1/2 – Bounded acceleration constraints
  • BSpline – General B-spline curves with configurable degree
  • ApproximationBSpline, CubicBSpline, InterpolationBSpline, SmoothingCubicBSpline

Motion Profiles

  • DoubleSTrajectory – S-curve profiles with bounded jerk
  • TrapezoidalTrajectory – Classic trapezoidal velocity profiles
  • PolynomialTrajectory – 3rd, 5th, 7th order polynomials
  • LinearPolyParabolicTrajectory – Linear segments with parabolic blends

Quaternion Interpolation

  • Quaternion – Core quaternion operations with SLERP
  • QuaternionSpline – C²-continuous rotation trajectories
  • SquadC2 – Enhanced SQUAD with zero-clamped boundaries
  • LogQuaternion – Logarithmic quaternion methods

Path Planning & Utilities

  • SimpleLinearPath, SimpleCircularPath – 3D geometric primitives
  • FrenetFrame – Frenet-Serret frame computation along curves
  • LinearInterpolation – Basic linear interpolation
  • TridiagonalInverse – Efficient tridiagonal system solver

Advanced Examples

Quaternion Rotation Interpolation
import matplotlib.pyplot as plt
from interpolatepy import QuaternionSpline, Quaternion

# Define rotation waypoints
orientations = [
    Quaternion.identity(),
    Quaternion.from_euler_angles(0.5, 0.3, 0.1),
    Quaternion.from_euler_angles(1.0, -0.2, 0.8)
]
times = [0.0, 2.0, 5.0]

# Smooth quaternion trajectory with C² continuity
quat_spline = QuaternionSpline(times, orientations, interpolation_method="squad")

# Evaluate at any time
orientation, segment = quat_spline.interpolate_at_time(3.5)
# For angular velocity, use interpolate_with_velocity
orientation_with_vel, angular_velocity, segment = quat_spline.interpolate_with_velocity(3.5)

# QuaternionSpline doesn't have built-in plotting - manual visualization needed
plt.show()
B-Spline Curve Fitting
import numpy as np
import matplotlib.pyplot as plt
from interpolatepy import CubicSmoothingSpline

# Fit smooth curve to noisy data
t = np.linspace(0, 10, 50)
q = np.sin(t) + 0.1 * np.random.randn(50)

# Use CubicSmoothingSpline with correct parameter name 'mu'
spline = CubicSmoothingSpline(t, q, mu=0.01)
spline.plot()
plt.show()
Industrial Motion Planning
import numpy as np
import matplotlib.pyplot as plt
from interpolatepy import DoubleSTrajectory, StateParams, TrajectoryBounds

# Jerk-limited S-curve for smooth industrial motion
state = StateParams(q_0=0.0, q_1=50.0, v_0=0.0, v_1=0.0)
bounds = TrajectoryBounds(v_bound=10.0, a_bound=5.0, j_bound=2.0)

trajectory = DoubleSTrajectory(state, bounds)
print(f"Duration: {trajectory.get_duration():.2f}s")

# Evaluate trajectory
t_eval = np.linspace(0, trajectory.get_duration(), 1000)
results = [trajectory.evaluate(t) for t in t_eval]
positions = [r[0] for r in results]
velocities = [r[1] for r in results]

# Manual plotting
plt.figure(figsize=(12, 8))
plt.subplot(2, 1, 1)
plt.plot(t_eval, positions)
plt.ylabel('Position')
plt.title('Industrial S-Curve Motion Profile')
plt.grid(True)
plt.subplot(2, 1, 2)
plt.plot(t_eval, velocities)
plt.ylabel('Velocity')
plt.xlabel('Time')
plt.grid(True)
plt.show()

Who Should Use InterpolatePy?

🤖 Robotics Engineers: Motion planning, trajectory optimization, smooth control
🎬 Animation Artists: Smooth keyframe interpolation, camera paths, character motion
🔬 Scientists: Data smoothing, curve fitting, experimental trajectory analysis
🏭 Automation Engineers: Industrial motion control, CNC machining, conveyor systems


Performance & Quality

  • Fast: Optional C++ backend (Eigen + pybind11) for maximum performance; pure-Python fallback uses vectorized NumPy
  • Reliable: 85%+ test coverage, continuous integration, 142 additional C++ unit tests
  • Modern: Python 3.11+, strict typing, dataclass-based APIs
  • Research-grade: Peer-reviewed algorithms from robotics literature

C++ Backend:

InterpolatePy includes an optional compiled C++ extension for performance-critical workloads. The API is identical regardless of backend:

import interpolatepy
print(f"C++ backend: {interpolatepy.HAS_CPP}")  # True if extension is available

Set INTERPOLATEPY_NO_CPP=1 to force pure-Python mode.

Typical Performance (pure-Python):

  • Cubic spline (1000 points): ~1ms
  • B-spline evaluation (10k points): ~5ms
  • S-curve trajectory planning: ~0.5ms

Development

Development Setup
git clone https://github.com/GiorgioMedico/InterpolatePy.git
cd InterpolatePy
uv sync                       # creates .venv with dev + test groups
uv run pre-commit install

# Run tests
uv run pytest tests/

# Run tests with coverage
uv run pytest tests/ --cov=interpolatepy --cov-report=html --cov-report=term

# Code quality
uv run ruff format interpolatepy/
uv run ruff check interpolatepy/
uv run mypy interpolatepy/

# Run all pre-commit hooks
uv run pre-commit run --all-files

Contributing

Contributions welcome! Please:

  1. Fork the repo and create a feature branch
  2. Install dev dependencies: uv sync
  3. Follow existing patterns and add tests
  4. Run uv run pre-commit run --all-files before submitting
  5. Open a pull request with clear description

For major changes, open an issue first to discuss the approach.


Support the Project

Star the repo if InterpolatePy helps your work!
🐛 Report issues on GitHub Issues
💬 Join discussions to share your use cases and feedback


License & Citation

MIT License – Free for commercial and academic use. See LICENSE for details.

If you use InterpolatePy in research, please cite:

@misc{InterpolatePy,
  author = {Giorgio Medico},
  title  = {InterpolatePy: Trajectory Planning and Interpolation for Python},
  year   = {2025},
  url    = {https://github.com/GiorgioMedico/InterpolatePy}
}
Academic References

This library implements algorithms from:

Robotics & Trajectory Planning:

  • Biagiotti & Melchiorri (2008). Trajectory Planning for Automatic Machines and Robots
  • Siciliano et al. (2010). Robotics: Modelling, Planning and Control

Quaternion Interpolation:

  • Parker et al. (2023). "Logarithm-Based Methods for Interpolating Quaternion Time Series"
  • Wittmann et al. (2023). "Spherical Cubic Blends: C²-Continuous Quaternion Interpolation"
  • Dam, E. B., Koch, M., & Lillholm, M. (1998). "Quaternions, Interpolation and Animation"

Built with ❤️ for the robotics and scientific computing community.

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

interpolatepy-3.1.0.tar.gz (525.7 kB view details)

Uploaded Source

Built Distribution

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

interpolatepy-3.1.0-py3-none-any.whl (117.4 kB view details)

Uploaded Python 3

File details

Details for the file interpolatepy-3.1.0.tar.gz.

File metadata

  • Download URL: interpolatepy-3.1.0.tar.gz
  • Upload date:
  • Size: 525.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for interpolatepy-3.1.0.tar.gz
Algorithm Hash digest
SHA256 7e49df5f7acd6d9eb62cb424e523a3a220d39209bf6b2ede288836dc60c40b45
MD5 26a8bb784ed64d7bc6e522c344e0ee60
BLAKE2b-256 c2f12687317e7019fa33065bbf37028ce737b7231e1efc07ed25719939a937b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for interpolatepy-3.1.0.tar.gz:

Publisher: publish.yml on GiorgioMedico/InterpolatePy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file interpolatepy-3.1.0-py3-none-any.whl.

File metadata

  • Download URL: interpolatepy-3.1.0-py3-none-any.whl
  • Upload date:
  • Size: 117.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for interpolatepy-3.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cfb0911e8b9fe4045c472fb9e6ad1ed035790710be900020ac1328762cc4ffd9
MD5 7a13a6bfa91f8def30a52c7e73339565
BLAKE2b-256 1ec155d62a4647828874488d0d524c5b4da3796cd11448f1b6ba7281f011ae86

See more details on using hashes here.

Provenance

The following attestation bundles were made for interpolatepy-3.1.0-py3-none-any.whl:

Publisher: publish.yml on GiorgioMedico/InterpolatePy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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