javascript - SVG implementation of Monotone cubic interpolation without a Library like d3 -


i'm trying draw path in svg draws smoothed curve between series of points.

for example - see (where "interpolations" set "monotone"):

http://bl.ocks.org/mbostock/4342190

i've found excellent implementation of algorithm in javascript here:

http://blog.mackerron.com/2011/01/01/javascript-cubic-splines/

i can use function create many points on curve want, , use points create polyline follow curve. huge number of points, i'd have relatively smooth curve.

but i'd able create path uses cubic bezier curves, d3 does.

i found svg implementation of catmull rom splines: https://gist.github.com/njvack/6925609

this works great, unlike monotone cubic interpolation, tends "overshoot" given points, isn't acceptable i'm doing.

obviously - use d3, i'd able without library, if @ possible.

thanks in advance.

you extract d3's implementation, in function called d3_svg_linemonotonetangents in src/svg/line.js:

// interpolates given points using fritsch-carlson monotone cubic hermite // interpolation. returns array of tangent vectors. details, see // http://en.wikipedia.org/wiki/monotone_cubic_interpolation function d3_svg_linemonotonetangents(points) {   // ...   return tangents; } 

permanent link d3_svg_linemonotonetangents in d3 v3.5.5.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -