Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spline of data points in 2 axis coordinate system bezierpath

I am trying to figure out a way to calculate the spline of data points in a 2 axis coordinate system to use as a bezierPath (Swift). BezierParth needs to have the correct shape and coordinates.

my data look like this and I am after a path like the red line...

Is that even possible?

Thank you in advance

my data look like this

like image 352
George Asda Avatar asked Jul 26 '18 17:07

George Asda


1 Answers

In sequence:

  1. Sort all your source data points by x
  2. Determine how many final data points you want and divide your X axis accordingly, this will determine how "smooth" your bezier is, or if you want it to go up/down on every data point, etc.
  3. Compute the average from the source data points into your final data points based on the x distance you computed
  4. Organize your final data points into an array
  5. Use some magic to render your final data points on a UIBezierPath

There is a really nice article on Medium.com at: https://medium.com/@ramshandilya/draw-smooth-curves-through-a-set-of-points-in-ios-34f6d73c8f9

It goes at length on how to render your UIBezierPath given a set of data points. Luckily, you don't have to understand all that magic, since the writer also made available his source code: https://github.com/Ramshandilya/Bezier

like image 84
ekscrypto Avatar answered Nov 16 '22 06:11

ekscrypto