My Problem is sort of solved, I overlooked, that paameters $B$ to $D$ are dependent on $x$ and $y$ one question remains, see bottom of question.

I implemented a periodic parametric cubic spline, and thus far it works fine. If I give it some points on a (unit) circle as support points, it allows me to plot a nice circle (round and everything). I am however interested in its second derivate for some curveature analysis. I thought to myself: Well, just calculate the derivates of the $y(t)$-portion and everything is going to be fine. That might have been a bit short sighted.

My basic spline is

\begin{align} S_x(t)&=A_{x,i} + B_{x,i}\cdot(t-t_i)+C_{x,i}\cdot(t-t_i)^2+D_{x,i}\cdot(t-t_i)^3\\ S_y(t)&=A_{y,i} + B_{y,i}\cdot(t-t_i)+C_{y,i}\cdot(t-t_i)^2+D_{y,i}\cdot(t-t_i)^3 \end{align}

where $t$ is the parameter along the spline, beginning at $0$ and ending at the splines length and $i$ denotes the support point at the begining of the interval my actual $t$ lies in.

If I want the cartesian point for any $x$, I can map my $x$ onto $t$ and retrieve the cartesian $y$-value of the spline at that point. As I said: It works very well with a full circle or $f(x)=x^2$ (ignoring the closing stroke). On moving to the derivates I thought it would be enough to just differentiate the $S_y(t)$, giving me:

\begin{align} S_y'(t)&=B_{y,i}+2\cdot C_{y,i}\cdot(t-t_i)+3\cdot D_{y,i}\cdot(t-t_i)^2\\ S_y''(t)&=2\cdot C_{y,i}+6\cdot D_{y,i}\cdot(t-t_i) \end{align}

These formulas however give me strange results. The first differentiation gives a linear graph, starting at (roughly) $(1|1)$ and moving down to $(-1|-1)$ before returning to $(1|1)$ again (moving clockwise around the circle, starting at $\varphi=0$). The second differentiation renders even stranger results: They follow roughly the outline of the circle, but seem "edgy" (so not smoothly distributed around it), with particular "edgyness" occuring at the support points.

A collegue pointed out to me, it might have something to do with the chain rule, since I'm still in parametric coordinates. So I rebuilt both derivates using numeric differentiation, which uses only values of $S_y(t)$, which have proven themselves to be "correctly aligned to my circle":

\begin{align} S_y'(t)&=\frac{S_y(t+h)-S_y(t-h)}{2\cdot h}\\ S_y''(t)&=\frac{S_y(t+h)-2\cdot S_y(t)+S_y(t-h)}{h^2} \end{align}

This was good for one thing: It showed, that my differentiation-skills could be worse :), the plots however didn't mind very much: they stayed the same. Evaluated with the quadratic function, the values in the range of about $[-0.5|0.5]$ fitted roughly what was to be expected of them, on the outside of this interval (most propably due to the alledged periodicity of the spline) they went a bit berzerk, but only a little.

What I expected:

For the circle I expected the following:

  1. The first differentiation should give me a curve going from $-\infty$ at $\varphi=0$ to $0$ at $\varphi=\pi/2$ (it does that at least), moving on to $\infty$ at $\varphi=\pi$ with a jump to $-\infty$ as we enter the half circle below the x-axis. From there on it is rising to $0$ at $3\pi/2$ and shooting up to $\infty$ as we approach $\varphi=2\pi$, giveng me a sort of diabolo-shape, only curved.
  2. If I remember correcty from my classes in "higher mathematics", the curvature of a circle is constant, evaluating to its radius. This is somewhat contrasted by the appearance of an edgy circle, circumscribing the original circle by a small margin in different places. On the other hand, that might have been in polar coordinates, so a transformation to carthesian coordinates would propably mess this nice result up a bit.

So here's the solved Question: What has gone wrong? My implementation (where?) or my presumptions on which results to expect (where?)?

The new question: If I evaluate the curvature of my circle, I get a graph which looks a bit like a piece of rope hanging between my support points. So between support points my curvature is lower than at the support points themselves. Also the curvature values at the support points are higher (+3% to +13%) than expected ($1$ was expected, as it is a unity circle) and drop to $-2%$ where the "ropey" parts are. Is this just a deficciency of the spline functions, or is something else wrong? I would expect the curvature to be at leas smooth, since this is a design characteristic of a spline, that the curvature is even and defferentiatable, isn't it? Example graph of unit circle with corresponding curvature (blue)


With parametric curves, things are a little more complex as the relation between $x$ and $y$ is indirect.

If you are looking for the slope at any point on the curve, this is given by $y'=\dfrac{dy}{dx}$ as usual, but you need to compute it as $\dfrac{dy/dt}{dx/dt}$, also denoted $\dfrac{\dot y}{\dot x}$, deriving with respect to $t$.

The second derivative is likewise $y''=\dfrac{dy'}{dx}=\dfrac{d(\dot y/\dot x)/dt}{dx/dt}=\dfrac{\ddot y\dot x-\dot y\ddot x}{\dot x^3}$.

In practice, when it comes to parametric curves, one does not work with $y'$ and $y''$ anymore, and prefer more isotropic quantities. In particular, the tangent vector and the curvature.

  • $\begingroup$ Hmm. But how do I go about "deparametrizing" $S_x(t)$ and $S_y(t)$? It seems quite complex to me... $\endgroup$ – lhiapgpeonk Jan 22 '15 at 14:50
  • $\begingroup$ Don't do that, keep the parametric form. If you really want to, you can use the Cardano-Tartaglia formulas and... get mad. $\endgroup$ – Yves Daoust Jan 22 '15 at 15:01
  • $\begingroup$ I think I will look into the tangent vector and curvature, and hope I need as little new formulas as possible :) $\endgroup$ – lhiapgpeonk Jan 22 '15 at 15:03
  • $\begingroup$ @lhiapgpeonk: you're lucky these are planar curves. In 3D things are getting harder, with tangent/normal/binormal and curvature/torsion :) $\endgroup$ – Yves Daoust Jan 22 '15 at 16:23
  • $\begingroup$ I had a look at my old notes. On evaluating the tangent vector $\dot{y}/\dot{x}$ I found it always evaluates to $1$, given the parametric form way up in my post. This somehow can't be right, can it? The second derivate won't be $1$ all the time, but given the odd first derivate, I'll bother about it later. $\endgroup$ – lhiapgpeonk Jan 26 '15 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.