We are developing an drawing application for iOS and android. I am using cubic quadratic curves to draw smooth curves because cubic Bézier curve is way slow to draw on mobile devices(mostly pads).
Drawing long quadratic curve with lot of points is still slow in pads so I am trying to reduce points I have to plot on canvas to speed up drawing.
I have tried,
- Catmull-Rom splines
- Ramer-Douglas-Peucker
but they are for cubic curves and not has not working properly for quad-curves.
Is there any algorithm or techniques for quad curves as well? can any other optimization be done to speed up path drawing?
You could subdivide the spline segment recursively, until they are almost a straight line.
where
Polyline-Length calculates the length of the poly-line formed by the control points.
StraightLineMeasure returns zero for a straight line, and a small number for almost straight lines.
Split returns two sets of control points, each of which represents half of the original curve.
B-Splines are easy to subdivide (pdf).
(click here for demo)
Here is an implementation in javascript: