The ability to render lines as smooth curves is a fairly frequent request. There are a number of algorithms floating around that use Android's cubicTo(...) and quadTo(...) methods but they all produce a line that overshoots it's control points, sometimes by a lot. What's needed is a Catmull-Rom spline interpolation algorithm.
For anyone brave enough to try, a basic implementation is now available. (click here to download) Along with the algorithm comes the interpolation interface allowing Androidplot users to write their own interpolation algorithms and plug them into an XYSeriesRenderer of their choosing. To enable catmull-rom interpolation on an XYSeries:
|
// initialize a formatter as normal: LineAndPointFormatter format = ... // configure interpolation on the formatter: format.setInterpolationParams( new CatmullRomInterpolator.Params(20, CatmullRomInterpolator.Type.Centripetal)); |
And that's it. Doing the above on the DemoApp's SimpleXYPlotActivity for "Series2" yields:
Fair warning: It's a work in progress, the algorithm is far from optimal and the interpolation interface may change.