# Limit rotation heading by cone/angle

What is a fast way of limiting the heading vector to a certain angle so that it turns in greater distance relative to the limit.

A smaller cone/angle should make the object take a far bigger curve to traverse to reach its goal where a larger cone/angel allows the object to rotate faster in the direction of its goal.

If there are some vector tricks i'll be glad to know them! • Are you asking how to constrain a vector to the inside of a cone, or are you asking about how to limit turn rate? (Limiting the turn rate based on a cone like this could make your turn rate very frame rate dependent) – Cholesky Nov 20 '12 at 21:10
• In this case both are somewhat similar. The cone represents the limit ( regardless of the angle )which limits the turning angle. – Sidar Nov 20 '12 at 21:39

## 1 Answer

This approach is familiar with the people in CNC machining: the CNC bit is carving a path on a metal surface. Characteristic to this process are some terms: feedrate - this is actually the speed at which the metal is "plowed" by the rotating head of the tool and direction of advance - this is your vector indicating the direction the bit will advance from its current position.

There are some common-sense limitations: the faster the metal is eaten away, the less the change in the advance direction. Again, imagine a car through a curve. If it's going slowly, it can negotiate quite tight corners, while when it's going fast, it cannot without straying from that curve and leaving the road which spells disaster.

Your problem is 100% depicting these scenarios. The mathematical skills you need involve the cross product (rotate the current advance direction to allow the object to home in on a target), axis-angle rotation and a transfer function (which is nothing more than a function that decreases with the speed of the object and tells how big your cone's angle is - just like a tolerance).

Some fast details:

• the discrete case involves a currentPosition, a targetPosition, a speed and a maxTurnAngle plus the currentDir (current direction of advance)
• at each step you compute the angle between crrentDir and targetPosition - currentPosition. This angle tells you by how much you should rotate currentDir to make the object go toward the target. Now you know your maxTurnAngle and you would like an estimate for how much you can turn. The idea is to safely divide the maxTurnAngle by an amount proportional to your speed. Then rotate currentDir against the cross product of currentDir and tgt - pos by that scaled angle. That should give you an idea.
• I assume that targetPosition-currentPosition are in this case vectors or the result should be applied as a vector against the currentDir to calculate the angle. What about turning the object left or right by using the cross product ( in 2D btw ) but then limit heading vector instead of calculating all that you described. Could you elaborate on this? – Sidar Aug 26 '12 at 19:37
• I was refering to this btw for cross-product: gamedev.stackexchange.com/questions/7131/… – Sidar Aug 26 '12 at 19:46
• tgtPos and currPos are vectors (actually, call them 3D points for less ambiguity), so tgtPos - currPos is the desired direction (modulo a normalization). Your currentDir needs to be rotated to be aligned with the desiredDir. Taking the cross product between currentDir X desiredDir you find the axis against which you need to rotate the current advance direction. From hereon, you may want to compute the maximum allowed turn angle for your current speed and then rotate being careful not to exceed this angle, if that's the case (i.e. turn too sharp). – teodron Aug 27 '12 at 6:31
• Page 27 of this paper tells you the exact details along with some pictures: docs.google.com/file/d/… – teodron Aug 27 '12 at 6:37