Coder Social home page Coder Social logo

bezier2arc's Introduction

bezier2arc

A program for modifying an SVG file containing line segments and cubic Bezier curves. Each cubic Bezier curve is approximated by a series of arc such that the maximum distance between the original Bezier spline and the arcs is less than a predefined tolerance. In addition, there is a lower limit to the radii of the arc segments that are used in the approximation. This is a constraint of some CNC machines.

This conversion program is useful when dealing with CNC programs that cannot handle Bezier curves.

The direct conversion to dxf format is planned but not yet implemented.

Prerequisites

  • svgpathtools
  • numpy
  • ezdxf
  • scipy

Setup

$ python setup.py install

Credit

The program borrows heavily from examples provided with the package svgpathtools. The iterative spline fitting logic is similar to the one described in A Primer on Bézier Curves.

Usage

# list all paths and segments in original file
$ python -m bezier2arc --list -i input.svg

# color the segments - useful for identifying errors in input file
$ python -m bezier2arc --color -i input.svg -o colored-input.svg

# convert to bezier splines to arcs, with minimum radius=50
# and maximum error=2
# units are the units of the input file
$ python -m bezier2arc --convert -i with-splines.svg -o with-arcs.svg -r 50 -d 2

# ... verify result
$ python -m bezier2arc --list -i with-arcs.svg

Examples

Color each segment of a svg file

$ python -m bezier2arc --color -i ./data/table-1-spline.svg -o table-1-spline-colors.svg

table-1-spline-colors.svg

License

This module is under a MIT License

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.