chaikinSmooth

tailrec fun chaikinSmooth(polyline: List<Vector2>, iterations: Int = 1, closed: Boolean = false, bias: Double = 0.25): List<Vector2>

Chaikin's corner cutting algorithm generates an approximating curve from a polyline

Interactive Demo

The code has been tweaked for performance instead of brevity or being idiomatic.

Parameters

polyline

a list of vectors describing the polyline

iterations

the number of times to approximate

closed

when the polyline is supposed to be a closed shape

bias

a value above 0.0 and below 0.5 controlling where new vertices are located. Lower values produce vertices near existing vertices. Values near 0.5 biases new vertices towards the mid point between existing vertices.