# Plotting parabolic segment of fixed length between points A & B

Given two points $A =(x_1,y_1)$, $B = (x_2,y_2)$ and length $L$, how do I plot a parabolic segment of length $L$ that connects A and B? The vertex of the parabola $(p, \, q)$ should be such that $x_1 \leq p \leq x_2$ and $q \leq y_1, y_2$.

In other words, I need to draw a parabolic segment connecting $A$ and $B$ with length $L$ that looks like a 'U' shape, with the vertex being below $A$ and $B$.

Thanks.

-

## migrated from stackoverflow.comMar 6 '11 at 21:43

This question came from our site for professional and enthusiast programmers.

You'll need three points to uniquely define a parabola -- there's an infinite number of concave-up parabolas passing through just two points. Can you restrict the parabola further? –  haldean Mar 6 '11 at 20:53

To amplify Beta's answer, if you write the equation as $y=a(x-b)^2+c$ the fact that the two points need to be on the parabola gives two equations in $a,b,c$. Your constraints on the vertex become constraints on $a, b$ and $c$. The arclength from $x_1$ to $x_2$ is $L=\left.\frac{1}{2a}\sqrt{1+4a^2(x-b)^2}+\frac{1}{2}\ln\left(2a(x-b)+\sqrt{1+4a^2(x-b)^2}\right)\right|_{x_1}^{x_2}$ and this is a third equation in $a$ and $b$. It looks like you are into a numeric solution, but you do have enough constraints.

-
$LaTeX$ help, please: how do I get a big vertical bar for evaluating the integral result at $x_1$ and $x_2$? –  Ross Millikan Mar 6 '11 at 23:12
Try \left. a^{b^c}_{d_e} \right\rvert_{x_1}^{x_2}, which renders as $\left. a^{b^c}_{d_e} \right\rvert_{x_1}^{x_2}$. (P.S. Also, I have to recommend using \LaTeX to get $\LaTeX$ instead of $LaTeX$.) –  Rahul Mar 7 '11 at 0:04
@Rahul: Works great. Thanks. Forgot the slash on $\LaTeX$ and too late to fix now. –  Ross Millikan Mar 7 '11 at 0:09
Thanks. Comparing your equation with that of Beta, I think you misplaced the closing bracket of ln funcion. Please verify. –  Vijay Krishna Mar 7 '11 at 5:06
@Vijay: you are right, but I took mine from Beta's, then edited Beta's post to put the $\LaTeX$ in. So you should check it, though the corrected version fits my general feel for integrals. –  Ross Millikan Mar 7 '11 at 5:13

Suppose we have a parabola defined by $y = a x^2$, with $a \gt 0$. Now we want to know its length between $x_1$ and $x_2$.

\begin{align} L &= \int dl \\ &= \int \sqrt{dx^2 + dy^2} \end{align}

$y = a x^2$

$dy = 2 a x dx$

\begin{align} L &= \int \sqrt{dx^2+ (2 a x dx)^2} \\ &= \int dx \sqrt{1+ (2 a x)^2} \end{align}

Now we look in a table of integral rules:
$\int \sqrt{1 + (kx)^2} = \frac{1}{k} \sqrt{1 + k^2x^2} + \frac{1}{2} \ln\left(kx + \sqrt{1 + k^2x^2}\right) + C$

Now comes the hard part: given x1, x2 and L, solve for a. This looks like a trancendental equation and offhand I don't see any clever way to solve it analytically. So you'll have to solve it numerically. A simple loop of code should do it; L increases strictly with a.

Shifting to the desired x1, x2, y1 and y2 is trivial (but notice that the problem appears to be underconstrained).

-
To enter equations, you enclose $\LaTeX$ between dollar signs. You can right click on any of that and choose Show Source to see how it was done. I hope I didn't do violence to your meaning when I formatted it. –  Ross Millikan Mar 7 '11 at 0:10
@Beta: Thanks for the reply. –  Vijay Krishna Mar 7 '11 at 5:05
@Beta: I made a correction based on Vijay's comments, but you are the one who checked the integral tables. Please make sure I got it right. Thanks –  Ross Millikan Mar 7 '11 at 5:17