Clamp angle between two vectors I'm programming a snake-type game in 3 dimensions without grid constraints where the location of the new 'block' is determined by:

[Normalized(lastBlockLocation - cursorLocation) * blockLength] + lastBlockLocation

where locations are 3D vectors and blockLength is an scalar. With this code, I make the snake follow the player without caring of the actual distance; however, I would also like to add a system to avoid too sharp angles.
So, here's the question: how can I clamp a vector so it has a maximun angle n with a know vector?
 A: You want the angle $\beta$ by which the snake changes its heading to be capped at some fixed angle $\beta_\text{max}$. I would separate detection from setting the new heading.  
Let $\mathbf u$ be a unit vector pointing in the current direction and $\mathbf u_\text{cursor}={\mathbf r_\text{cursor}-\mathbf r\over\|\mathbf r_\text{cursor}-\mathbf r\|}$ a unit vector in the direction of the cursor relative to the last block location. Then the change in direction is too large if $\mathbf u\cdot\mathbf u_\text{cursor}=\cos\beta\lt\cos{\beta_\text{max}}$.  
If the change in angle is small enough, proceed as before. If not, you need to rotate $\mathbf u$ by $\beta_\text{max}$ toward the cursor. There are several ways to do this, but I think the following is one of the more efficient. Compute the orthogonal rejection $\mathbf v_\perp=\mathbf u_\text{cursor}-(\mathbf u\cdot\mathbf u_\text{cursor})\mathbf u$. You’ve already got this dot product from the previous step. Then, the clamped new direction will be given by the unit vector $$\mathbf u_\text{clamped}=\cos\beta_\text{max}\mathbf u+\sin\beta_\text{max}{\mathbf v_\perp\over\|\mathbf v_\perp\|}.$$ The sine and cosine of $\beta_\text{max}$ can of course be precomputed.  
The case $\mathbf u_\text{cursor}=-\mathbf u$, i.e., the cursor is directly behind the snake, will need special handling. You’ll need to pick a direction—clockwise or counterclockwise—and a plane for the change in heading. [Addition] One possibility is to save the most recent previous heading $\mathbf u_\text{prev}\ne\mathbf u$ and use $-\mathbf u_\text{prev}$ instead of $\mathbf u_\text{cursor}$ to compute the clamped direction change in this case. That will turn the snake in a manner consistent with its most recent direction change.
A: I found a way to do it that isn't that mathematical, but it gives pretty nice results. Instead of checking if the change in direction is too big, I simply lerp between my current direction and the target direction with this formula:
Direction = (TargetDirection - Direction) / Speed
To see this formula in action, refer to http://www.somethinghitme.com/2013/11/13/snippets-i-always-forget-movement/ (the Move Towards an Object With Easing)
This not only prevents the snake from turning too much or too fast; it also makes the motion much more fluid and nice
