Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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.

share|improve this question
    
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. –  Robotbugs Mar 5 '13 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. –  Robotbugs Mar 5 '13 at 2:18

2 Answers 2

up vote 2 down vote accepted

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$:

enter image description here

share|improve this answer
    
OK thats great because its just $\frac{kx}{x+c}$ which is very few math operations. I can precompute the two constants. –  Robotbugs Mar 5 '13 at 6:24
    
By the way, does your robot have bugs or are your robots shaped like bugs? :) –  Rahul Mar 5 '13 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:) –  Robotbugs Mar 5 '13 at 6:31
1  
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. –  Rahul Mar 5 '13 at 6:35
1  
OK well you'll be pleased to know that your answer is now incorporated into my iPad app. –  Robotbugs Mar 5 '13 at 8:46

I constructed a quadratic Bezier curve (somewhat like your b-spline idea), and then converted it to $y = f(k,\alpha)$ 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$

graphs

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.

share|improve this answer
    
Thanks, thats exactly the form of curve I was looking for. I can certainly live with a square root function. Many thanks! –  Robotbugs Mar 5 '13 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. –  Robotbugs Mar 5 '13 at 5:43
    
You have a mix of $k$ and $x$ in there. Are they supposed to be the same variable? –  Robotbugs Mar 5 '13 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. –  bubba Mar 5 '13 at 10:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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