A comprehensive TypeScript library for working with B-splines of arbitrary dimension in arbitrary vector spaces. Built with mathematical rigor and computational efficiency in mind, this library provides a flexible foundation for B-spline operations and algorithms.
Each operation supports multiple algorithm implementations that can be selected based on your needs:
- De Boor's algorithm (stable and general purpose)
- Optimized evaluation for uniform B-splines
- Educational step-by-step implementation
const curve = new BSplineCurve2D(controlPoints, degree, {
evaluation: new DeBoorEvaluation(), // Default stable algorithm
// OR
evaluation: new OptimizedEvaluation(), // Performance-focused
// OR
evaluation: new EducationalEvaluation(), // Clear step-by-step implementation
});
- Boehm's knot insertion algorithm
- Oslo algorithm for knot refinement
- Knot removal with error control
const refinedCurve = curve.insertKnot(0.5, {
algorithm: new BoehmsInsertion() // Classical algorithm
// OR
algorithm: new OsloAlgorithm() // Better for multiple insertions
// OR
algorithm: new AdaptiveInsertion() // Automatic error control
});
- Degree elevation with various bases
- Degree reduction with error control
const elevatedCurve = curve.elevateDegree({
method: new BernsteinElevation(), // Using Bernstein basis
// OR
method: new PowerBasisElevation(), // Using power basis
// OR
method: new AdaptiveElevation(), // Automatic error control
});
- Symbolic differentiation
- Automatic differentiation
- Finite difference methods
const derivative = curve.derivative({
method: new SymbolicDerivative(), // Exact derivatives
// OR
method: new AutomaticDerivative(), // Efficient for higher orders
// OR
method: new FiniteDifference(), // Numerical approximation
});
- Direct multiplication
- FFT-based multiplication for uniform B-splines
- Adaptive multiplication with error control
const product = f.multiply(g, {
algorithm: new DirectMultiplication(), // Standard algorithm
// OR
algorithm: new FFTMultiplication(), // Fast for uniform B-splines
// OR
algorithm: new AdaptiveMultiplication(), // Automatic precision control
});
- Classical polar form computation
- Optimized evaluation for specific cases
const blossomValue = curve.blossom([u1, u2, u3], {
method: new ClassicalBlossom(), // Standard implementation
// OR
method: new OptimizedBlossom(), // Performance-focused
// OR
method: new SymbolicBlossom(), // Symbolic computation
});
- Support for B-splines of any dimension (functions, curves, surfaces, volumes)
- Works with arbitrary vector spaces (ℝⁿ, ℂⁿ, or custom spaces)
- Extensible design for adding new algorithms and spaces
- Type-safe implementation in TypeScript
- Both readable "educational" and optimized implementations
- Comprehensive test coverage
- Well-documented mathematical foundations
The library supports interchangeable algorithms for core operations:
// Choose between different algorithm implementations
const curve = new BSplineCurve2D(controlPoints, degree, {
evaluation: new OptimizedEvaluation(), // Fast evaluation
knotInsertion: new BoehmsInsertion(), // Boehm's algorithm
multiplication: new FastMultiplication(), // Optimized multiplication
});
// Or use convenient factory methods
const educationalCurve = BSplineFactory.createEducational(
controlPoints,
degree
);
const optimizedCurve = BSplineFactory.createOptimized(controlPoints, degree);
// Create a cubic B-spline curve in 2D with automatic knot vector generation
const curve = new BSplineCurve2D(
[
[0, 0], // Control points as [x, y] coordinates
[1, 1],
[2, 0],
[1, -1],
[0, 0],
],
3
); // Degree 3 (cubic)
// Evaluate the curve at parameter value
const point = curve.evaluate(0.5); // Returns [x, y] point
// Get curve derivatives
const tangent = curve.derivative(1); // First derivative
const curvature = curve.derivative(2); // Second derivative
// Modify the curve
const refinedCurve = curve.insertKnot(0.3); // Knot insertion
const elevatedCurve = curve.elevateDegree(); // Degree elevation
// Create two B-spline functions (1D B-splines)
const f = new BSplineFunction(
[
1, // Control points as scalar values
2,
0.5,
1,
],
2
); // Quadratic B-spline
const g = new BSplineFunction(
[
0.5, // Control points as scalar values
1,
1.5,
],
1
); // Linear B-spline
// Multiply the functions
const product = f.multiply(g);
// Evaluate the product at a parameter value
const value = product.evaluate(0.5); // Returns scalar value
// The resulting B-spline maintains mathematical properties:
console.log(product.degree); // Sum of input degrees (2 + 1 = 3)
console.log(product.domain); // Intersection of input domains
console.log(product.controlPoints.length); // New control point count
// Functions can be manipulated before/after multiplication
const refined = f.insertKnot(0.5).multiply(g.elevateDegree());
// Create a cubic B-spline curve in 3D space
const curve = new BSpline(
vectorSpace3D, // Vector space definition
controlPoints, // Control points in 3D
knotVector, // Knot vector
3 // Degree
);
// Evaluate the curve
const point = curve.evaluate(0.5);
// Compute the derivative
const derivative = curve.derivative();
// Insert a knot
const refinedCurve = curve.insertKnot(0.3);
npm install b-spline-algorithms
This library is under active development. Current focus:
- Core B-spline evaluation algorithms
- Basic operations (knot insertion, degree elevation)
- Foundation for arbitrary vector spaces
- Documentation of mathematical concepts
Coming soon:
- Additional vector space implementations
- Advanced algorithms (subdivision, intersection)
- Performance optimizations
- More examples and tutorials
Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.
-
Fork the repository
-
Clone your fork
-
Install dependencies
-
Create a feature branch
-
Make your changes
-
Run tests
-
Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
List any references, papers, or other libraries that inspired or informed your implementations
-
Create an issue on our GitHub repository for bug reports or feature requests
-
Submit pull requests for contributions
- 0.0.1
- Initial release
- Basic B-spline functionality
- Periodic curve support