Git Product home page Git Product logo

fitcurves's Introduction

fitCurves

Python implementation of Philip J. Schneider's "Algorithm for Automatically Fitting Digitized Curves" from the book "Graphics Gems"

Fit one or more cubic Bezier curves to a polyline.

This is a python implementation of Philip J. Schneider's C code. The original C code is available on http://graphicsgems.org/ as well as in https://github.com/erich666/GraphicsGems

The python implementation uses NumPy

demo.py is a example gui application using Tkinter.

demo

fitcurves's People

Contributors

volkerp avatar

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  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

fitcurves's Issues

What data type is the points?

I'd like to avoid installing Tkinter at this time.

What data type is Points in fitCurve?

We can see that leftTangent = normalize(points[1] - points[0]) they can't just be a list of [[x,y], [x1,y1]] because that would be an illegal operation.

def fitCurve(points, maxError):
    leftTangent = normalize(points[1] - points[0])
    rightTangent = normalize(points[-2] - points[-1])
    return fitCubic(points, leftTangent, rightTangent, maxError)

directly compared the variable with zero may cause bugs

alpha_l = 0.0 if det_C0_C1 == 0 else det_X_C1 / det_C0_C1

Try to fit this bad case:
points: [[1605.99181736 1433.82668586]
[1608.81290918 1436.66242932]
[1612.4412136 1438.2910418 ]]
leftTangent:[0.65773635 0.75324822] rightTangent:[-0.71222538 -0.70195086]

I think changed to fabs(_) < 1e-3 is better, and would solve the problem.

Inaccuracy reproducing a bezier

When you get samples points from an existing bezier, and fit a curve to those points, the original bezier is inaccurately reconstructed.

>>> import bezier
>>> from fitCurves import fitCurve
>>> import numpy as np
>>> import sys
>>>
>>> points = np.array([[0, 0], [5,50], [50,40], [75,50]], dtype=np.float32)
>>> samples_t = np.linspace(0, 1, 100, dtype=np.float32)
>>> samples_pt = [bezier.q(points, t) for t in samples_t]
>>> calculated_bezier = fitCurve(samples_pt, sys.float_info.max)
>>>
>>> print(calculated_bezier)
[[array([0., 0.], dtype=float32), array([ 4.945499, 45.22236 ], dtype=float32),
array([42.795097, 37.474834], dtype=float32), array([75., 50.], dtype=float32)]]

>>> print(np.array(calculated_bezier) - points)
[[[ 0.          0.        ]
  [-0.05450106 -4.7776413 ]
  [-7.2049026  -2.5251656 ]
  [ 0.          0.        ]]]

(I am very grateful for your port of this function to python!)

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.