Member-only story
Using De Casteljau’s Algorithm/Bezier Curves in SwiftU
Apple’s Bezier curves code is good, but sometimes you need to dig deeper

I wrote an article the other day about using Bezier curves, the construction of which is built into Swift primitives. It’s super useful and works really well. Within that article, I mentioned in passing that the math behind it was mind-boggling. I was wrong. The math is simple. It’s the code that mind-boggling. Let’s dig deeper.
But wait, just before we jump in, why would you want to go down this rabbit hole? Here are three possible scenarios:
- The client wants you to plot some text on a Bezier curve.
- You want to use a set of Bezier coordinates for a game.
- You’re concerned with making the app run faster, and calculating fewer points for a Bezier curve would make sense.
But if you wanted to do any and/or all of these, you’d be stuck because the Apple primitives don’t return coordinates. They return a path. You need to dig deeper. Let’s try to do the math and the code.
As I mentioned last time, the man of the moment is De Casteljau, who wrote the algorithm to do what mathematicians call linear interpolation between two values. The algorithm calculates the coordinates needed to draw…