A Primer on Bézier Curves
pomax.github.io
pomax.github.io
https://github.com/artursapek/mondrian/blob/master/src/coffe...
It's a wall of this:
c11.x*c12.y*c13.x*c13.y*c23.x*c23.y - c11.y*c12.x*c13.x*c13.y*c23.x*c23.y + 6*c21.x*c22.x*c13y3*c23.x +
3*c11.x*c12.x*c13.x*c13.y*c23y2 + 6*c10.x*c13.x*c13y2*c23.x*c23.y - 3*c11.x*c12.x*c13y2*c23.x*c23.y -
3*c11.y*c12.y*c13.x*c13.y*c23x2 - 6*c10.y*c13x2*c13.y*c23.x*c23.y - 6*c20.x*c13.x*c13y2*c23.x*c23.y +
3*c11.y*c12.y*c13x2*c23.x*c23.y - 2*c12.x*c12y2*c13.x*c23.x*c23.y - 6*c21.x*c13.x*c22.x*c13y2*c23.y -
6*c21.x*c13.x*c13y2*c22.y*c23.x - 6*c13.x*c21.y*c22.x*c13y2*c23.x + 6*c21.x*c13x2*c13.y*c22.y*c23.y +
Maybe there's a way to refactor it, but I wouldn't know because I still don't understand it; I just know that it works.If anyone is really interested in this stuff and wants to make a major contribution to open source software... First study these and then move on to NURBS, surfaces, and then trimmed NURBS surfaces. These are the core of all CAD software and a clean library for trimmed NURBS is sorely lacking. There are two that I'm aware of, the one in OpenCascade which is a huge ball of mud (but works) and the one in SolveSpace which doesn't scale well and has some other limitations - that is the one I feel is most worthy of someones time.
Intersections are computed approximatively within some prescribed geometrical tolerance, and intersection curves are "marched out".
BTW they don't explicitly say "trimmed NURBS" but doing boolean operations implies that is the case ;-)
NLib has a lot of sophisticated NURBS math tools. It was literally written by one of the men who wrote The NURBS Book.
As far as I know, it doesn't do anything much for trimmed NURBS surfaces, in the sense of a surface trimmed by an arbitrary series of curves. (Might be a tessellation routine for that case?) Basically it is mostly geometry, with only very limited topology support.
There are lots of products which provide geometry & topology support: SMLib, SOLIDS++, Acis, and Parasolid come to mind. The first two are built on NLib. I don't think any of them have as sophisticated NURBS geometry tools as NLib does. (Except to the extent that you can call NLib routines directly with the first two.)
I'm not aware of any commercial product which directly competes with NLib at all. Which doesn't mean one doesn't exist! I'd be interested if anyone has experience with other libraries.
https://en.wikipedia.org/wiki/Parasolid
Look at the list of applications that use it.
I would guess the factors of 3 and 6 arise from derivatives of the cubics: x^3 derives to 3x^2 derives to 6x.
I believe NURBS stands for Nobody Understands Rational B-Splines [0] :)
[0] http://www.springer.com/productFlyer_978-3-540-61545-3.pdf?S... (pdf)
https://www.reddit.com/r/ProgrammerHumor/comments/4xzi9a/oh_...
http://stackoverflow.com/questions/5072758/spline-smoothing-...
I converted Algol code from a paper into C because I couldn't find any clean C code on the web but it's still ugly eg. here is a chunk of it:
for (i=m1; i < m2; i++) //Choleksy Decomposition {(R^T)R of [(Q^T)(D^2)Q + pT]}
{
r1[i-1] = f*r[i-1];
r2[i-2] = g*r[i-2];
r[i] = 1/(p*b[i]+t[i]-f*r1[i-1]-g*r2[i-2]);
u[i] = a[i]-r1[i-1]*u[i-1]-r2[i-2]*u[i-2];
f = p*c[i]+t1[i]-h*r1[i-1];
g = h;
h = d[i]*p;
}If it's the latter, how did you keep your sanity?
The latest improvement is that the codebase now supports localization which means that if you're a dual (triple, etc) speaker and you want to help bring this content to people who don't speak English, now you can! Chinese and Japanese localizations are already underway (although it's a volunteer effort, much like the Primer itself, so progress is again steady, but slow) and currently cover the first 10 or so sections.
For more details on the fine points of the build system and how much work it was to overhaul an "everything is assumed to be English, no l10n provisions have been made whatsoever" to "EASY to localize" (not just 'possible to', but 'easy'), hit up http://pomax.github.io/1489108158510/localization-is-hard where I've blogged about the uplift and the tech choices I made.
And on a less impressive note but certainly more useful for social sharing, the social share buttons now actually point to the section you're reading, so that future sections can be shared waaay easier. For the last six years, those things have just pointed to the base article URL and that is not very useful when you want to share the fact that you just read up on how to split a Bézier curve using matrix operations, or want to link to the B-Spline section all the way at the bottom of the Primer.
2017: https://news.ycombinator.com/item?id=14155393
Also if you use search, there are some more high profile SVG related posts that don't follow that made up pattern.
My suggestion is, think you could create an "applications of beziers" page which lists common bezier use cases? eg. Draw a curved path. Animate using easing. Animate along a curve. Animate along a curve with an ease. Then link from there to only to the sections you'd need to learn and apply to get to that application? It would be infinitely more helpful to new learners.
The Primer would then remain a great resource as a standalone. And the Applications page would be a great navigation and learning resource page for people looking to start.
Feature request: please expand the spline section or make a similar, separate primer on splines.
I'd just like to make an annoying mathematician comment on the beginning (paragraph 3): you might want to point out that the first definition you give of Bézier(n,t) is, for any n and t, nothing else than the constant function 1 (that, by the way, is an absolutely fine polynomial, unlike the statement above that if f(x) has no x then it's not a polynomial).
You can see this by noting that it's nothing else than $((1-t)\cdot t)^n = 1^n = 1$. If you insist on being fancy, you can say that the i-th term in the sum is the probability of a discrete random variable X with binomial law being equal to i, so the sum over all i must be 1 (here the binomial law has parameters (n,t)).
By the way, this last thing has the nice interpretation that each point of the Bézier curve is just the expected value of $p(X)$, where $p(0), \dots, p(n)$ are the points you are interpolating - by changing t you are just changing the parameter of the random variable.
> In this paper we prove that, for cubic Catmull-Rom curves, centripetal parameterization is the only parameterization in this family that guarantees that the curves do not form cusps or self-intersections within curve segments.
http://www.cemyuksel.com/research/catmullrom_param/catmullro...
(speaking as someone who gets slightly twitchy whenever he sees interpolated animations go bad)
https://github.com/melling/ComputerGraphics/blob/master/bezi...
That makes them a hell of a lot more intuitive for imagining "how will my modifications affect the curve?"
Thanks for sharing.
[1] In Racket, here: https://github.com/piotrklibert/curved-text
> They're named after Pierre Bézier . . . publishing his investigations in 1962
> One might be tempted to say that the mathematician Paul de Casteljau was first,
investigating the nature of these curves in 1959
> Bézier curves are, at their core, "Bernstein polynomials",
a family of mathematical functions investigated by Sergei Natanovich Bernstein,
with publications on them at least as far back as 1912.
I see many stories like this, which shatter the idea of a lone inventor bringing something new out of thin air.(It's been around a while but this is a rewrite and looks like a pretty massive update)
That said, early higheschoolers knows jack about binomials unless they are particularly smart. I would venture a majority of college students (in subjects other than engineering and science) would find this too daunting. I think by downplaying the complexity it actually turns people off from trying to learn. Which of course is a shame.
Well.... If it was so easy, why does the algorithm have a name? (Bresenham's algorithm), if it's named surely it must've been "invented" at some point, implying it wasn't as easy?