How to draw smooth line through many points


#1

Is there any easy way to draw smooth line through many points?
I know quadraticTo can do this through two points, and cubicTo make it for three points.
But what if I need to do that through 10 points?
Do I really need to make some complicated math? Isn’t there any function to do that easly?


#2

That’s not how you use quadraticTo, here is a thread with a graphic of the parameters explained:

And here is your previous thread:

You will have to calculate the control vertices yourself out of each three consecutive points.
The tangent should be the orthogonal to the half enclosed angle.


#3

Thanks for reply. So the answer is “no” - there is not any ready to use method to make smooth line that goes through many points.
So really all audio analyser graphs use that complicated math to calculate the control points?


#4

Your problem leaves too much ambiguity for a generic solution. So you will have to do a little maths on your own…


#5

Use a Path and draw your graph with straight lines and then use Path::createPathWithRoundedCorners(). I’ve done that before and it looks pretty good.

I also have a spline class that might work for you:


#6

Hey G-Mon it looks great. But it doesn’t work for me. I make it like that:

for(int i=0; i<something; i++) {
    myPath.lineTo(/*some code*/);
}
myPath.createPathWithRoundedCorners(10.0f);

And my line is still sharped. What am I doing wrong here?


#7

Path::createPathWithRoundedCorners() returns a new path:

Path roundedPath = myPath.createPathWithRoundedCorners(10.0f);
g.strokePath(roundedPath, PathStrokeType(...));

#8

Aha :slight_smile:


#9

Now it works, great thanks


#10

Just wondering about radius. I see when I set radius above some value there is no changes. For radius in range 1-30 it works as I expect, but above 30 for example 100 or 500, it looks the same as for 30.


#11

Above a certain range you’ll have more points than will be noticeable on screen. When I was using this method on an earlier project I found a value of 16 was enough to get a good looking result