<p>There are a couple different approaches to endpoint interpolation with splines.</p>
<p>One way is to add an additional point to either end of the curve, which is not part of the original data set. Moving this invisible &quot;guide&quot; point around will change the shape of the end segments of the curve. So, if you have <span class="math-container">$n$</span> actual data points, you'd use <span class="math-container">$n+2$</span> points for the spline interpolation, with <span class="math-container">$2$</span> &quot;guide&quot; points. <em>(Note that you would have the curve itself not pass through these guide points, but just use them for tangent calculations.)</em></p>
<p>Another way is to take a one-sided difference. This, in a sense, &quot;clamps&quot; the calculation within the boundaries of the data set. For example, with an equation like this:
<span class="math-container">$$p_i-p_{i-1}+p_{i+1}$$</span>
For the <span class="math-container">$n=0$</span> case, you can just take
<span class="math-container">$$p_0-p_0+p_1$$</span>
By replacing out-of-bounds points with a boundary point. Similarly, for <span class="math-container">$i=n$</span>, we get <span class="math-container">$p_n-p_{n-1}+p_n$</span>.</p>
<p>This means any <span class="math-container">$i-1$</span> is calculated as <span class="math-container">$\max(i-1,0)$</span> and <span class="math-container">$i+1$</span> is <span class="math-container">$\min(i+1,n)$</span>, for points <span class="math-container">$p_0,p_1,\dots,p_n$</span>.</p>
<p>I've found that a one-sided difference tends to give visually reasonable results and doesn't require choosing any &quot;guide&quot; points.</p>

CC BY-SA 4.0
2024-08-25T17:03:30.283Z
I was looking for a way to generate them algorithmically, but I guess there really isn't one.
Chifti Saidi
CC BY-SA 4.0
2024-11-05T16:29:39.180Z
@ChiftiSaidi What I described *is* how to generate them algorithmically. If you're looking for something more specific you'd need to give more information on the program which you're doing this in.
e4494s
CC BY-SA 4.0
2024-07-17T19:54:12.657Z
2024-07-17T19:54:12.657Z
e4494s
<p>I'm working on a program which uses Kochanek-Bartels ("TCB") splines.</p>

<p>My question is: How do I deal with the first/last points of the spline?</p>

<p>This type of spline needs a 'previous' and 'next' point at each node to generate the curve tangents, but the first and last points on the curve don't have them. How do graphics programs deal with this problem?</p>

<curve>
How should I generate Kochanek-Bartels spline endpoints?
Chifti Saidi
# How should I generate Kochanek-Bartels spline endpoints?

(Asked by: username_0 on 2018-07-17)

I'm working on a program which uses Kochanek-Bartels ("TCB") splines.

My question is: How do I deal with the first/last points of the spline?

This type of spline needs a 'previous' and 'next' point at each node to generate the curve tangents, but the first and last points on the curve don't have them. How do graphics programs deal with this problem?

**Tags:** curve


---

## 1 answers

### Answer by username_1 on 2024-07-17. Score: 1

There are a couple different approaches to endpoint interpolation with splines.

One way is to add an additional point to either end of the curve, which is not part of the original data set. Moving this invisible "guide" point around will change the shape of the end segments of the curve. So, if you have $n$ actual data points, you'd use $n+2$ points for the spline interpolation, with $2$ "guide" points. *(Note that you would have the curve itself not pass through these guide points, but just use them for tangent calculations.)*

Another way is to take a one-sided difference. This, in a sense, "clamps" the calculation within the boundaries of the data set. For example, with an equation like this:
$$p\_i-p\_{i-1}+p\_{i+1}$$
For the $n=0$ case, you can just take
$$p\_0-p\_0+p\_1$$
By replacing out-of-bounds points with a boundary point. Similarly, for $i=n$, we get $p\_n-p\_{n-1}+p\_n$.

This means any $i-1$ is calculated as $\max(i-1,0)$ and $i+1$ is $\min(i+1,n)$, for points $p\_0,p\_1,\dots,p\_n$.

I've found that a one-sided difference tends to give visually reasonable results and doesn't require choosing any "guide" points.

> **Comments:**
> **username_0**: I was looking for a way to generate them algorithmically, but I guess there really isn't one.  
> **username_1**: @username_0 What I described *is* how to generate them algorithmically. If you're looking for something more specific you'd need to give more information on the program which you're doing this in.  

---

