[Math] How to find tangent at any point along a cubic hermite spline

spline

I have a cubic hermite spline path that I am using to move sprites around on the screen (2D). I use two end points and two tangents to define the curve and then I use the basis functions for interpolation:

\begin{equation*}
h_1(t) = 2t^3 – 3t^2 + 1\\
h_2(t) = -2t^3 + 3t^2\\
h_3(t) = t^3 – 2t^2 + t\\
h_4(t) = t^3 – t^2
\end{equation*}

What I want to do is have my sprite point in the direction of the curve as it is traveling along it. As I understand it from searching, the tangent to the curve (which I am assuming is the direction I want my sprite to face) involves taking the derivative of the function, however my calculus is severely lacking and once I do have the derivative, what do I do with it? Will it give me a new set of basis functions where I can just plug in a time t and get the tangent at that location?

Best Answer

You just take the first derivative of your basis functions as

$h'_1(t)=6t^2-6t$
$h'_2(t)=-6t^2+6t$
$h'_3(t)=3t^2-4t+1$
$h'_4(t)=3t^2-2t$

and this is your new set of basis functions for computing first derivative of the cubic Hermite curve. You will do the same computation as you would for computing points on the curve but using this new set of basis functions.

Once you have compute the first derivative vector, normalize it into a unit vector and that is your tangent vector.