Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Approximation of Bezier Curves using biarcs #332

Open
cbrunschen opened this issue Nov 16, 2021 · 2 comments
Open

Approximation of Bezier Curves using biarcs #332

cbrunschen opened this issue Nov 16, 2021 · 2 comments

Comments

@cbrunschen
Copy link

The section on approximating Bézier curves using circular arcs will generally result in an approximation that has discontinuous derivatives - corners, where ever the approximation switches from one arc to another; i.e.whereas the Bézier curve is G1-continuous, the approximation through circular arcs is not. This is easily seen in the interactive example: with a big enough error tolerance, there are clear gaps and overlaps between the circle sectors corresponding to adjacent arcs:

See this image

There is a technique to approximate curves using 'biarcs', where two circular arcs are combined to approximate a single section of a curve.

See for example:

This allows both the start and end points and their derivatives to be maintained, while also ensuring that where the two component arcs of the biarc meet, they too have the same derivative.

In other words, this would result in an approximation that maintains the pleasant property of Bézier curves that they are G1 continuous, which the current approximation is not.

I think this would be an excellent addition to, or perhaps even replacement for, the current section on how to approximate Bézier curves with circular arcs.

Related links of potential interest might be:

@Pomax
Copy link
Owner

Pomax commented Nov 16, 2021

Oh nice, thank you!

I don't think it'd be a replacement, more an "advanced" notes div in the section on arcs: given what arc approximation does, having C1 continuity doesn't really give us anything important since any under the hood maths you'd be doing, you'd still use the bezier formulae for. The arc approximation is really only something you use for the final "drawing the thing" in a paths-only context that doesn't have bezier draw/plot primitives, and to get a usable arclength parameterization so that you can find approximate points-at-a-distance directly, rather than needing derivatives.

Biarcs would mostly solve the problem of viewing prerendered curves at high magnification, where an arc transition might look discontinuous, but that's pretty niche - good to mention as "if you need that" section, but it solves a problem that most folks will rarely (if ever) run into.

@cbrunschen
Copy link
Author

Glad you like it :)

Biarcs would indeed allow generating the approximation once and then viewing that at arbitrary resolution, without having to re-approximate, and while still remaining smooth. But I don't think that's the only or most important use case,

Circular arcs can also also useful for offsetting from the path, for example.

A circular-arc approximation also allows for easy constant-speed motion along the path, which can be useful in animation including for games for example, and there, the smoothness of any direction change may well be an important factor. See also this blog post which also seems to have useful further links.

Another relevance is where you mention 'fabrication machinery' - a lot of CNC machines may accept commands to move along a line or along an arc, but may not support Bezier curves, so an approximation using arcs may reduce the required file size / command stream bandwidth required; and when it comes to machining things, I think that where there is G1-continuity in the input, preserving that in the approximation may well be a useful property (keeping things smooth and not adding unexpected corners / kinks).

And at least theoretically, a CNC machine might use something Bresenham-like to step along a circular arc at the finest possible mechanical resolution, much like it might do to step along a line, in which case a sequence of arc commands may give a better and much smoother approximation of the curve than a (longer) sequence of line segments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants