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?

For the sake of simplicity, let's start with this scenario:

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*+(*b*–*ma*)" 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=tan*^{2}x 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=x*^{c} — with *c* properly calculated from *a*, *b*, and *m* — could also be a solution.

Perhaps even an exponential function based around *y=e*^{x} could be made to work.

What suggestions do you have? Please explain your solutions!

Thanks,

~ Justin

1 Attachment(s)

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

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 $\displaystyle f(0)=f'(0)=0$ :

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

When $\displaystyle x=1$, this function evaluates to $\displaystyle 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 $\displaystyle f(0)=f'(0)=0$ and that all intersect (1,1) can be defined as follows:

$\displaystyle 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 *x*^{k} would. Where *k*=0, the function is undefined, but the limit as *k* approaches zero from either side is simply *y*=*x*^{2}. 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 $\displaystyle f'(a)=m$ .

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

$\displaystyle 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 $\displaystyle f_3'(a)=m$ . Because of the way we scaled $\displaystyle f_2(x)$ to obtain $\displaystyle f_3(x)$ , by reversing the scaling we should be able to determine that $\displaystyle 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 $\displaystyle f_2(x)$ . If I did, I could substitute $\displaystyle f_2'(1)=m(a/b)$ and solve for *k* in terms of *m*, *a*, and *b*. Any help?

~ Justin

Re: Ways to construct a spline curve connecting two points

**johng**: Thanks for responding. I followed your solution as far as...

$\displaystyle a_2a^2+a_3a^3=b$

$\displaystyle 2a_2a+3a_3a^2=m$

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

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

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

Can you please clarify?

Thanks,

~ Justin

1 Attachment(s)

Re: Ways to construct a spline curve connecting two points

Hi,

I hope the attachment clarifies things:

Attachment 28931

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?

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 $\displaystyle f_2(x)$

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

Differentiating with respect to *x* yields: ^{$\displaystyle u'=ke^x-k$} and ^{$\displaystyle v'=0$} .

Now, the Quotient Rule tells us that

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

Therefore

$\displaystyle 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

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

Remember that, as explained above,

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

Therefore

$\displaystyle \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 $\displaystyle k$ on only one side of this equation. Help?

Re: Ways to construct a spline curve connecting two points

Can anyone help solve the last equation above for *k* ?