Coder Social home page Coder Social logo

ajunlonglive / tinyspline Goto Github PK

View Code? Open in Web Editor NEW

This project forked from msteinbeck/tinyspline

0.0 0.0 0.0 4.19 MB

ANSI C library for NURBS, B-Splines, and Bézier curves with interfaces for C++, C#, D, Go, Java, Javascript, Lua, Octave, PHP, Python, R, and Ruby.

License: MIT License

CMake 14.61% C 48.95% C++ 9.63% Shell 3.00% SWIG 3.67% Makefile 0.04% Dockerfile 1.53% Python 0.84% C# 0.80% Go 0.39% Java 0.75% Lua 15.28% Ruby 0.51%

tinyspline's Introduction

TinySpline

CI Security Language Grade: C/C++

TinySpline is a small, yet powerful library for interpolating, transforming, and querying arbitrary NURBS, B-Splines, and Bézier curves. The core of the library is written in ANSI C (C89) with a C++ wrapper for an object-oriented programming model. Based on the C++ wrapper, auto-generated bindings for C#, D, Go, Java, Javascript, Lua, Octave, PHP, Python, R, and Ruby are provided.

License

MIT License - see the LICENSE file in the source distribution.

Features

  • Object-oriented programming model
  • B-Splines of any degree and dimensionality
  • Spline interpolation
    • Cubic natural
    • Centripetal Catmull–Rom
  • Evaluation
    • Knots
    • Sampling (multiple knots at once)
    • Equidistant points
    • Components (find y for given x)
  • Reparametrization by arc length
    • Mapping length <--> knot
  • Knot insertion (refinement)
  • Bézier curve decomposition
    • (also known as subdivision)
  • Derivative
  • Degree elevation
  • Computation of rotation minimizing frames
  • Morphing
  • Serialization (JSON)
  • Vector math

Installation

Pre-built Binaries

Releases can be downloaded from the releases page. In addition, the following package manager are supported:

Conan (C/C++):
https://conan.io/center/tinyspline

NuGet (C#):

<PackageReference Include="tinyspline" Version="0.5.0.1" />

Go:

go get github.com/tinyspline/[email protected]

Luarocks (Lua):

luarocks install --server=https://tinyspline.github.io/lua tinyspline

Maven (Java):

<dependency>
   <groupId>org.tinyspline</groupId>
   <artifactId>tinyspline</artifactId>
   <version>0.5.0-1</version>
</dependency>

PyPI (Python):

python -m pip install tinyspline

On macOS, you probably need to change the path to Python in _tinysplinepython.so via install_name_tool.

RubyGems (Ruby):

gem install tinyspline --pre

Compiling From Source

See BUILD.md.

Getting Started

A variety of examples (unit tests) can be found in the test subdirectory. The examples subdirectory contains at least one example for each interface (target language).

The following listing shows a python example:

from tinyspline import *
import matplotlib.pyplot as plt

spline = BSpline.interpolate_cubic_natural(
  [
     100, -100, # P1
    -100,  200, # P2
     100,  400, # P3
     400,  300, # P4
     700,  500  # P5
  ], 2) # <- dimensionality of the points

# Draw spline as polyline.
points = spline.sample(100)
x = points[0::2]
y = points[1::2]
plt.plot(x, y)

# Draw point at knot 0.3.
vec2 = spline.eval(0.3).result_vec2()
plt.plot(vec2.x, vec2.y, 'ro')

# Draw tangent at knot 0.7.
pos = spline(0.7).result_vec2() # operator () -> eval
der = spline.derive()(0.7).result_vec2().normalize() * 200
s = (pos - der)
t = (pos + der)
plt.plot([s.x, t.x], [s.y, t.y])

plt.show()

The resulting image:

Getting Started

Theoretical Backgrounds

[1] is a very good starting point for B-Splines.

[2] explains De Boor's Algorithm and gives some pseudo code.

[3] provides a good overview of NURBS with some mathematical background.

[4] is useful if you want to use NURBS in TinySpline.

tinyspline's People

Contributors

egradman avatar giorgiomarcias avatar giumas avatar gnimuc avatar ilgarlunin avatar julianoes avatar justinthomas avatar kwikius avatar luzpaz avatar madebr avatar marco-langer avatar msteinbeck avatar queengooborg avatar trikko avatar vanxining avatar wmamrak avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.