Pomax / BezierInfo-2

The development repo for the Primer on Bézier curves, https://pomax.github.io/bezierinfo
https://pomax.github.io/bezierinfo
Other
2.29k stars 286 forks source link

How do we derive control points from `start`, `end`, `B` and `t` #323

Closed luc4leone closed 2 years ago

luc4leone commented 2 years ago

In section 30

For cubic curves, there is no single pair of points that can act as e1 and e2: as long as the distance ratio between e1 to B and B to e2 is the Bézier ratio (1-t):t, we can reverse engineer v1 and v2

@Pomax the above is not clear to me and I feel it's crucial to understand, can you please elaborate it further?

Also:

Pomax commented 2 years ago

The first set looks like it uses notation that matched a previous graphic, those primes shouldn't be there (fixed in https://github.com/Pomax/BezierInfo-2/commit/e89f11a84a8bd7e7eb22b4a666d36e172cbbac8c). As for the second function, what part is not clear? Those are the v1 and v2 values that we computed two lines up, and is further explained by looking at the graphic again, which explains what e1/e2 and v1/v2 are.

image

The formula are just the math expressions for the already stated natural English descriptions of what we see in the graphic:

And the same applies to the control points. Looking at the graphic, we can express "where they can be found" in terms of distances from the start/end point based on the distances between start--v1 and end--v2 and the fact that those distances represent t and 1-t fractions respectively of the "line segments to the control points".

luc4leone commented 2 years ago

Hey @Pomax, first of all thanks. A couple of questions.

first question

If

e1 = (1-t)*v1 + t*A

I get calculate v1 in a couple of steps:

e1 - t*A = (1-t)*v1

then

e1 - t*A / 1-t = v1

which is different from

image

where's my mistake?

second question

For cubic curves, there is no single pair of points that can act as e1 and e2

what do you mean exactly?

Pomax commented 2 years ago

1) that's a good point, it looks like that formula for v1/v2 isn't correct, and should be updated. However, note that you do have a mistake: if e1 - t*A = (1-t)*v1 then that becomes (e1 - t*A) / (1-t) = v1, not e1 - t*A / (1-t) = v1.

2) note that the text doesn't say "there is no pair of points", but "there is no single pair of points". There are infinitely many pairs of e1 and e2 that we could use, each yielding a different final curve, based on the fact that the tangent at B is not fixed for cubic curves (unlike for quadratic curves), so it's up to us as designers/implementers to pick what seems a reasonable pair with which to perform the curve construction.

Updates in https://github.com/Pomax/BezierInfo-2/commit/272af23fe42663241e392eebc30764d84e958e86

luc4leone commented 2 years ago

then that becomes (e1 - t*A) / (1-t) = v1, not e1 - t*A / (1-t) = v1

absolutely, I missed the parenthesis, but yeah, what you wrote is what was on my mind, my bad!