formula for representing a logarithmic spiral as of cubic bezier curve segments

511 Views Asked by At

I need to write an algorithm that approximates joined cubic bezier curve segments into a logarithmic spiral curve. How can I achieve this?

2

There are 2 best solutions below

3
On

The primordial property of a logarithmic spiral is its selfsimilarity. Your algorithm should make good use of that fact. In what follows I assume the spiral as presented in the form $$\gamma:\quad t\mapsto\left\{\eqalign{x(t)&=\cos (2\pi t)\>e^{\lambda t} \cr y(t)&=\sin (2\pi t)\>e^{\lambda t} \cr}\right.\qquad(-\infty<t<\infty)$$ with given $\lambda\in{\mathbb R}$, whereby $|\lambda|$ should not be all too big for good results. Choose an $N\in{\mathbb N}$ and define $t_k:={k\over N}$ $(k\in{\mathbb Z})$. Then split up $\gamma$ into arcs $\gamma_k$ $(k\in{\mathbb Z})$ defined by $$\gamma_k:\quad \tau\mapsto\left\{\eqalign{x(\tau)&=\cos \bigl(2\pi( t_k+\tau)\bigr)\>e^{\lambda (t_k+\tau)} \cr y(\tau)&=\sin \bigl(2\pi( t_k+\tau)\bigr)\>e^{\lambda (t_k+\tau)} \cr}\right.\qquad\left(0\leq \tau\leq{1\over N}\right).$$ Let $$\beta_0:\quad \tau\mapsto\left[\matrix{x_0(\tau)\cr y_0(\tau)\cr}\right]\qquad \left(0\leq \tau\leq{1\over N}\right)$$ be the Bézier (or some other) approximation of $\gamma_0$. Computing $\beta_0$ is your business. You should make sure that ${\rm arg}\bigl(x_0'(1/N),y_0'(1/N)\bigr)={\rm arg}\bigl(x'(0),y'(0)\bigr)+{2\pi\over N}$. Then $$\beta_k:\quad\tau \mapsto T^k\left[\matrix{x_0(\tau)\cr y_0(\tau)\cr}\right]$$ is the Bézier approximation to $\gamma_k$; furthermore $\gamma_{k-1}$ and $\gamma_k$ concatenate smoothly. Here $T$ is the matrix $$T=e^{\lambda/N}\left[\matrix{\cos{2\pi\over N}&-\sin{2\pi\over N}\cr \sin{2\pi\over N}&\cos{2\pi\over N}\cr}\right]$$ which increases the argument (polar angle) of each point by ${2\pi\over N}$ and scales everything by the factor $e^{\lambda/N}$. Note that $$T^{k+N}=e^\lambda\> T^k\ ;$$ which simplifies the numerical calculations.

0
On

I suppose that quadratic bezier curves and NO higher order are required. That is, 3 points: an initial, a control, and a final.

Seeing the wikipedia page of the logarithmic spiral it is seen that using polar coordinates and that the tangent line of the curve with respect to the line of the radius always form the same angle. P.e. in the photo of the spiral of the wiki: 10 degrees.

For the 3 first points, of the quadratic Bezier segment, it is easy, we choose the points that are on the x axis and on the y axis (pi / 2 of angle in polar coordinates):

$Point 1: (1, 0)$

$Point 2, control: (c, d)$

$Point 3: (0, e ^ {(\pi / 2) b})$

$Point 2$ must be the crossing of the lines:

$A:$ Line parallel to the "$y$" axis, which passes through point 1, but rotated an "$alpha$" angle to the right on point 1.

$B$: Line parallel to the "$x$" axis, which passes through point 3, but rotates an angle also "$alpha$" to the right on point 3.

You have to calculate then c, and d from b:

First we calculate the angle (and that depends on b):

$$alpha = pi / 2 - arctan (1 / b)$$

And then the two tangent lines and the point where they intersect are calculated.

Example, starting the reverse, for a "pitch" of 10 degrees, I will calculate b:

$$b = cotan (10º) = 1 / tan (80º) = 0.1763 ...$$

Point 1: (1,0)

Point 3: (0,1.3191)

(Every quarter of a turn of the spiral, the distance to the center is multiplied by 1.3191 and forms an angle of 10º with respect to the axes, in this example).

Let $k = e ^ {(\pi / 2) b} = 1.3191$

Line A: $y = (x-1) / b$

Line B: $y = k - b x$

$k - bx = x / b - 1 / b$

$k + 1 / b = x (b + 1 / b)$

$x = (k + 1 / b) / (b + 1 / b) = c$

$y = k - b c = d$

$c = 1.1954$

$d = 1.1084$

Point 2: $(1.1954, 1.1084)$

And those are the 3 points of a Bezier Quadratic curve for a quarter of a turn of a logarithmic spiral of pitch 10º (photo from the wiki).