Approximating a natural function spiral with a finite series of straight lines and constant curvature circle segments

approximationcirclesgeometryMATLABpython

I am in need of bending a wire to a spiral shape defined by

$$
r(\phi)=a + b\phi + c\phi^2+d\phi^3
$$

My bending machine is capable of bending circle segments with a constant radius $R$ and angle $\alpha=n\cdot \alpha_0$ and feeding straight wire with the length $l=n\cdot l_0$ where $n$ is an integer number and $\alpha_0,l_0$ are machine parameters.

Another constraint is that every straight line needs to be tangent to the next circle segment and that every circle segment needs to be followed by a straight segment, and vice versa.

Below is an image of a circle approximated by this method, but I am not sure how it would relate to a spiral path.

enter image description here

Does anybody have an idea how I could generate a series of circle segments and straight lines that approximates my curve with above constraints (i.e. $n\in \mathbb{N}$) such that the area integral between the original curve and the approximate path is minimized?

Ideally I would want a matlab or python script that outputs LRA (or YBC) coordinate data which is what a typical bending machine takes. ( LRA stands for length, rotation, angle for every segment where rotation would be required for a 3D shape but is not used in this case.)

Best Answer

Abstractly, we're given a regular parametrized plane curve—possibly a polar graph $r = f(\phi)$ for $a \leq \phi \leq b$, possibly a Cartesian path $(x(t), y(t))$ for $a \leq t \leq b$—and the goal is to approximate the image by a finite sequence of

  1. Line segments of fixed length $\ell_{0}$ [sic],
  2. Circle arcs of fixed radius $R$ and angular size $\alpha_{0}$ [sic].

Qualitatively, we have three types of curve atom (or two if an arc can bend only leftward), and we want to build a molecular chain whose shape approximates the target path.

An approximation scheme may be viewed as constructing a finite sequence of segments-and-arcs. Because successive atoms are tangent at their common endpoints (as stipulated in an edit), the position and orientation of any particular atom locks in most of the freedom: There is a two-parameter family of initial positions and a one-parameter family of initial angles; after that there are only finitely many choices in total.

For definiteness, I'll assume arcs can bend in two directions (left and right). One geometrically natural idea is to approximate the signed curvature of the target path. For a regular (non-vanishing velocity) Cartesian parametrization $(x(t), y(t))$ with $a \leq t \leq b$, the signed curvature is $$ k(t) = \frac{x'(t)y''(t) - x''(t)y'(t)}{(x'(t)^{2} + y'(t)^{2})^{3/2}}. $$ To use this, we need to normalize in terms of arc length. Define $$ s = \sigma(t) = \int_{a}^{t} \sqrt{x'(\tau)^{2} + y'(\tau)^{2}}\, d\tau, $$ let $t = \sigma^{-1}(s)$ denote the inverse functional relationship, and finally define the signed curvature as a function of arc length $$ \kappa(s) = k(t) = k(\sigma^{-1}(s)). $$ The function $k$ can generally be found analytically; the arc length parameter $s$ may involve a "non-elementary" integral, and in any case the functional inversion needed to write the path parameter $t = \sigma^{-1}(s)$ in terms of arc length generally can be found only numerically.

Those difficulties aside, our problem is fairly simple. Using the machine parameters in the question, we want to approximate the curvature function $\kappa$ of the target path with a piecewise-constant function whose values are either $0$ on intervals of length $\ell = n\ell_{0}$, or else $\pm 1/R$ on intervals of length $\alpha R = n\alpha_{0}R$. (If the machine can only bend wire to the left, discard the value $-1/R$ coming from bending to the right.) That in turn is a matter of iteratively inspecting the values of $\kappa$ along the "next prospective interval," choosing one of the three (or two) available values, and (not) bending the wire accordingly.

To carry out this scheme in practice (for "tame" target shapes in a practical sense), it suffices to

  • Calculate the curvature function $k(t)$ for $a \leq t \leq b$;
  • Calculate the arc length function $s = \sigma(t)$ for $a \leq t \leq b$, or numerically approximate at a resolution suitably finer that the machine's smallest parameters ($\ell_{0}$ and $\alpha_{0}R$);
  • Numerically approximate the inverse function $t = \sigma^{-1}(s)$, and tabulate the resulting values of the arc length-normalized curvature $\kappa(s)$.

That leaves rather a lot of numerical and logical coding, but is mathematically well-founded and looks feasible to implement.