Finding a simple spline-like interpolating function

I am looking for a continuous function $y=f(x,\alpha)$ for the interval $0\le x \le 1$ such that $0\le y \le 1$ and $y(0,\alpha)=0$ and $y(1,\alpha) = 1$ and $y(\alpha,\alpha) = 1-\alpha$ and $dy/dx|_{x=\alpha}=1$. It is effectively symmetrical about the line $y=1-x$. Typically $0.2\le \alpha \le 0.8$.

It looks like a parabola but rotated so that the new y axis is along $y=1-x$, but since I need to be able to compute $y$ given $x$, I have not yet been able to work it out.

The exact form is not too important, but since this is to go in a OpenGL vertex shader I am trying to come up with something that is as simple as possible in terms of math operations.

• I tried using a b-spline with three control points at $(0,0)$, $(\alpha,1-\alpha)$, and $(1,1)$ and it looks ok when plotted but the problem is its in a parametric form depending on $t$ and getting a simple $y=f(x,\alpha)$ out of it is painful. Mar 5, 2013 at 1:09
• I'm currently using code: if(d<alpha) d = (1.0-alpha)*d/alpha; else d = (1.0-alpha)+(d-alpha)*alpha/(1.0-alpha); to do a simple 2 piece linear interpolation. The point of my question is finding something smoother and possibly faster to compute. Mar 5, 2013 at 2:18

The solution by @bubba is quite nice, but if by "It looks like a parabola but rotated", you don't mean that it necessarily is exactly a parabola, then you can get a slightly simpler expression by using a rotated hyperbola instead. The general form for a hyperbola with axis-aligned asymptotes is $$y=p\frac{x+q}{x+r}.$$ Plugging in your conditions gives $$p=\frac{(1-\alpha)^2}{1-2\alpha}, \quad q=0, \quad r=\frac{\alpha^2}{1-2\alpha},\\ y=\frac{(1-\alpha)^2x}{(1-2\alpha)x+\alpha^2}.$$ Here are the graphs of the function for $\alpha=0.1,0.2,\ldots,0.9$:

• OK thats great because its just $\frac{kx}{x+c}$ which is very few math operations. I can precompute the two constants. Mar 5, 2013 at 6:24
• By the way, does your robot have bugs or are your robots shaped like bugs? :)
– user856
Mar 5, 2013 at 6:26
• Actually my previous statement was false as I realize that introduces a singularity at $\alpha = 0.5$. (Its amazing how little appears on a screen when you have Infs in a vertex shader.) And I guess robotbugs could be both:) Mar 5, 2013 at 6:31
• Yes, if you write it as $kx/(x+c)$ then there is a singularity, but if you write it as $kx/(hx+c)$ like in my final formula then there is no singularity.
– user856
Mar 5, 2013 at 6:35
• OK well you'll be pleased to know that your answer is now incorporated into my iPad app. Mar 5, 2013 at 8:46

I constructed a quadratic Bezier curve (somewhat like your b-spline idea), and then converted it to $y = f(\alpha, x)$ form. The result is:

$$y = \frac{1 + 4 \alpha (x-1)-2 x+\sqrt{(1-4 \alpha)^2+8 (1-2 \alpha) x}}{2-4 \alpha}$$

My guess is that this isn't very good for your purposes because of the square root.

Also, this formula only works for values of $\alpha$ with $0.25 \le \alpha \le 0.75$.

Here are the graphs of these functions for $\alpha = 0.25, 0.35, 0.45, 0.55, 0.65, 0.75$

They are all (rotated) parabolas.

The $0.25 \le \alpha \le 0.75$ restriction could be lifted by using a rational quadratic curve, instead. But the square root won't go away, so I want to know if you can live with that before I spend time working out the details of the rational case.

• Thanks, thats exactly the form of curve I was looking for. I can certainly live with a square root function. Many thanks! Mar 5, 2013 at 5:40
• Also what did you use to display such a nice graph on here? I was wondering how to get a diagram in my original post. Last time I tried to post something though I did not have enough standing on the forum to post images. Mar 5, 2013 at 5:43
• You have a mix of $k$ and $x$ in there. Are they supposed to be the same variable? Mar 5, 2013 at 5:44
• Sorry. I used k instead of alpha in my calculations, and forgot to change some of them back to alpha. I'll fix it. To insert a picture, you just click on the picture icon above the editing pane. Mar 5, 2013 at 10:16