How to draw smooth line through many points

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?

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.

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?

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

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:
https://forum.juce.com/uploads/short-url/4RSMXTpIwnq4ylFO5Q9R8O0e8Sn.jpg

3 Likes

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?

`Path::createPathWithRoundedCorners()` returns a new path:

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

Aha

Now it works, great thanks

1 Like

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.

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