PDA

View Full Version : Cubic Bezier approximation using circular arcs and lines



Madav Ramanuj
3rd July 2016, 12:38
Hi,

I'm working on a project where the program generate the QPainterPaths, later this path will be converted to GRBL commands and fed to the CNC machines.
I see from the QPainterPath source most of the paths of arcs, ellipse and curve are converted/drawn using cubic bezier curve by calling cubicTo.
Unfortunately GRBL provides commands for only arcs and lines.

So the bezier curve need to be converted/approximated in to set of arcs and lines before the bezier curve can be drawn by the machine.
So can someone please let me know how this can be achieved in Qt?

what I'm tying to achive is same as mentioned in these document.

Cubic bezier approximation
http://ac.els-cdn.com/S0377042796000568/1-s2.0-S0377042796000568-main.pdf?_tid=10054424-40cd-11e6-a0ac-00000aab0f26&acdnat=1467516196_4d834409d16fc84d0915fa82b6afe5bc

Quadratic bezier approximation
http://ac.els-cdn.com/0377042794903980/1-s2.0-0377042794903980-main.pdf?_tid=3f290ed0-40c2-11e6-887b-00000aab0f6c&acdnat=1467511550_a096d6d8d563c64111642e0e264dd6c7

Uwe
3rd July 2016, 13:28
One option is to use QPainterPath::toSubpathPolygons(), but the implemented subdivision is tailored for rendering to screen, what means it terminates for a "flatness" value of 0.5 ( going deeper doesn't make sense, when everything is rounded to 1 pixel later ).

If you need something more flexible you could have a look at https://sourceforge.net/p/qwt/code/HEAD/tree/trunk/qwt/src/qwt_spline.cpp. QwtSplineBezier::toPolygon() offers an implementation depending on a flatness parameter, one you can set on application side. The implementation is based on "Piecewise Linear Approximation of Bézier Curves" by Roger Willcocks ( http://www.rops.org ).

Uwe