GithubHelp home page GithubHelp logo

ideasman42 / curve-fit-nd Goto Github PK

View Code? Open in Web Editor NEW
94.0 9.0 18.0 114 KB

High level utility library that takes a line and fits a bezier curve to it, in any number of dimensions - usable for freehand drawing and tracing raster images.

License: BSD 3-Clause "New" or "Revised" License

C 63.72% CMake 1.56% Python 34.72%

curve-fit-nd's Introduction

Curve Fit nD

Cubic curve fitting library.

https://cloud.githubusercontent.com/assets/1869379/17393989/1f8f21ba-5a6a-11e6-82cb-9d7cda155825.png

Example showing a cubic spline fit to 283 points.

Usage

This is a high level utility library that takes a line and fits a Bézier curve to it, in any number of dimensions - usable for freehand drawing and tracing raster images.

Intended for use cases where you simply want to input a line defined by a series of points and get back a Bézier curve that fits within an error margin.

By supporting multiple dimensions, this allows for 2D and 3D curve fitting, however you may want to define other properties such as radius along the curve, color, opacity... or other properties. Having arbitrary number of dimensions allow for this.

Use Cases

Origin

The method used here can be found in graphics gems FitCurve.c (by Philip J. Schneider, 1990).

This implementation was taken from OpenToonz, with some additional improvements.

Fitting Method

This uses a least square solver from the original graphics gems example.

However some improvements have been made.

  • Arbitrary number of dimensions.

  • Replace bound-box clamping with a distance limit from the weighted center.

  • Improved fallback methods, when the least square solution fails.

    This includes:

    • Circle fit: which accurately fits the curve to a circle.
    • Offset fit: which uses the offset of the curve to calculate handle length.
  • Re-fitting, an alternate, a more computationally intensive method for knot placement which initializes the curve as a dense curve (where every point is a knot), then iteratively removing knots which give the least error, some further adjustments are made after this to avoid local-maximums giving skewed results. This also has the advantage that it can be used to detect corners.

Source Code Layout

  • c/: the main C library.
  • c_python_ext/: a Python3 wrapper for the C library.
  • tests/: test files for the library, written in Python, using c_python_ext.

curve-fit-nd's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

curve-fit-nd's Issues

Parameters default values

Hey @ideasman42,
Thanks for this amazing work!
In a context of hand drawn curves, I'm trying to set good values for the different parameters for curve_fit_corners_detect_db and curve_fit_cubic_to_points_refit_db

Not so easy.
Do you recommend any typical values or ranges?

FYI, I tried on a basic case: a square (40 points per side) and I can't get good result for all angles:

image

What's the entry point for this lib?

Hi Campbell,
I hope you are doing well.

I'm trying to figure out how to use this library with a set of 2d points.

Could you please let me know where I should start with this.

Thanks,
Jeremy Bullock (turtletooth)

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.