# Ways to construct a spline curve connecting two points

• Jul 29th 2013, 01:53 PM
jdmc
Ways to construct a spline curve connecting two points
What are the various ways to construct a smooth (or at least continuously differentiable) curve that passes through two arbitrary points, given the slope of the curve at the two points?

Find a function f(x) defined on the interval [0,a] that passes horizontally through the origin [f(0) = f'(0) = 0] and passes through point (a,b) with slope m. You may assume that:

• a > 0
• b > 0
• m > (a/b) [and therefore m > 0]
• f(x) >= 0
• f'(x) >= 0

In other words, you're looking for a spline curve that tangentially intersects the lines "y=0" and "y=mx+(bma)" at (0,0) and (a,b), respectively. (Note that the x-intercept of the latter line is at x>0.)

I've been trying to come up with solutions based on functions that satisfy f(0)=f'(0)=0 and which curve upward as x increases, scaled to fit into the box defined by (0,0) and (a,b) with the proper slope at (a,b), but I'm having trouble.

One thing I tried was scaling an arc of a circle. But I soon realized that there is only one possible circle whose center lies on the y axis and which passes through both (0,0) and (a,b), meaning an arbitrary slope value at (a,b) cannot be accommodated. (However, if the circle center is allowed to be to the right of the y axis, in some cases a circle arc could be found that tangentially intersects the x axis at x>0, with the function defined as y=0 between there and the origin.)

Next I tried a parabolic (2nd-order polynomial) function. But I couldn't figure out how to scale it in such a way that an arbitrary slope at (a,b) was possible.

A hyperbolic function might be workable, but I haven't tried it.

The trig-derived function y=tan2x seems promising, but again, I couldn't figure out the scaling.

I know a Bézier curve could be used, but I'm looking for a solution that can be expressed as a non-parametric equation.

I think a power function based around some version of y=xc — with c properly calculated from a, b, and m — could also be a solution.

Perhaps even an exponential function based around y=ex could be made to work.

Thanks,
~ Justin
• Jul 29th 2013, 08:08 PM
johng
Re: Ways to construct a spline curve connecting two points
Hi,
The easiest spline through your two given points (0,0) and (a,b) with required tangents is a cubic polynomial. See the attachment:
Attachment 28929
• Jul 29th 2013, 08:31 PM
jdmc
Re: Ways to construct a spline curve connecting two points
I've been playing around with exponential functions, and came up with a form that satisfies $f(0)=f'(0)=0$ :

$f_1(x)=e^x-x-1$

When $x=1$, this function evaluates to $e-1-1=0.71828\cdots$ . The function can be scaled to intersect (1,1) by dividing it by this figure.

A family of related functions that all satisfy $f(0)=f'(0)=0$ and that all intersect (1,1) can be defined as follows:

$f_2(x)=\frac{e^{kx}-kx-1}{e^k-k-1}$

What I found is that this family of functions has some interesting properties. As k approaches positive infinity, the plot hugs the x axis, then shoots straight up at x=1, much like xk would. Where k=0, the function is undefined, but the limit as k approaches zero from either side is simply y=x2. And the limit as k approaches negative infinity appears to be y=x.

What I'm thinking is that this family of functions that intersect (1,1) could simply be scaled to intersect (a,b) instead, with the value of k selected so that $f'(a)=m$ .

First, the scaling. We can "stretch" the function $y=f(x)$ which intersects (1,1) to intersect (a,b) instead by making it $y=b*f(x/a)$ .

$f_2(x)=\frac{e^{kx}-kx-1}{e^k-k-1}\ \ \implies\ f_3(x)=b*f_2(x/a)=b\left(\frac{e^{k(x/a)}-k(x/a)-1}{e^k-k-1}\right)$

We're almost there! Now we just have to figure out the correct value of k so that $f_3'(a)=m$ . Because of the way we scaled $f_2(x)$ to obtain $f_3(x)$ , by reversing the scaling we should be able to determine that $f_2'(1)*(b/a)=f_3'(a)=m\implies f_2'(1)=m(a/b)$ .

Unfortunately, that's where I'm stuck, as I don't know how to differentiate $f_2(x)$ . If I did, I could substitute $f_2'(1)=m(a/b)$ and solve for k in terms of m, a, and b. Any help?

~ Justin
• Jul 29th 2013, 09:30 PM
jdmc
Re: Ways to construct a spline curve connecting two points
johng: Thanks for responding. I followed your solution as far as...

$a_2a^2+a_3a^3=b$

$2a_2a+3a_3a^2=m$

...but I'm not seeing how you get from there to:

$a_2=\frac{3b-am}{a^2}$

$a_3=\frac{ma-2b}{a^3}$

Thanks,
~ Justin
• Jul 30th 2013, 06:58 AM
johng
Re: Ways to construct a spline curve connecting two points
Hi,
I hope the attachment clarifies things:

Attachment 28931
• Jul 30th 2013, 09:06 AM
jdmc
Re: Ways to construct a spline curve connecting two points
Well done, johng! I had forgotten all about Cramer's Rule, and I missed the multiplication-then-subtraction approach you demonstrated. Thanks!

Can a general solution also be found using only a second-order polynomial?
• Jul 30th 2013, 08:28 PM
jdmc
Re: Ways to construct a spline curve connecting two points
Quote:

Originally Posted by jdmc
Unfortunately, that's where I'm stuck, as I don't know how to differentiate $f_2(x)$

Let $u=e^{kx}-kx-1$ and $v=e^k-k-1$ . Then $f_2(x)=u/v$ .

Differentiating with respect to x yields: $u'=ke^x-k$ and $v'=0$ .

Now, the Quotient Rule tells us that

$\frac{d}{dx}\left(\frac{u}{v}\right)=\frac{u'v-uv'}{v^2}$

Therefore

$f_2'(x)=\frac{(ke^x-k)(e^k-k-1)-(e^{kx}-kx-1)(0)}{(e^k-k-1)^2}=\frac{ke^x-k}{e^k-k-1}$

so

$f_2'(1)=\frac{ke-k}{e^k-k-1}$

Remember that, as explained above,

$f_2'(1)=\frac{ma}{b}$

Therefore

$\frac{ma}{b}=\frac{ke-k}{e^k-k-1}=\frac{k(e-1)}{e^k-k-1}\ \implies k=\frac{ma(e^k-k-1)}{b(e-1)}$

Unfortunately, I'm having trouble isolating $k$ on only one side of this equation. Help?
• Oct 4th 2013, 09:40 AM
jdmc
Re: Ways to construct a spline curve connecting two points
Can anyone help solve the last equation above for k ?