maybe a good way of seeing the problem is to ask :
- can i do another cycle ?
count the number of cycle, and see if this is the begining
of a cycle:
var beginingNewCycle=false;
numCycle = Math.floor ( (angle - endAngle ) / 6.28318531 ;
if (old_numCycle != numCycle) beginingNewCycle=true;
old_numCycle=numCycle;
( when the rotation starts,
you should : 1) reset angle with angle=angle % 6,28318531 ;
and 2) set old_numCycle to -1
)
So when you have a new cycle, ask yourself if this will be the last,
for example if speed < threshold.
Then you do the last turn controlling the speed fade-out to zero.
for instance for the fade out, you can use :
var rotSpeedAtenuation = 1 - ( (angle-EndAngle) % 6.28318531 ) / 6.28318531 ;
which is a number going from 1 to 0 linearly as angle gets nearer from goal.
multiply the speed by this number, but keep a minimum speed not to freeze the
object before arrival.
But linear might be hugly, maybe you want to 'shape' the atenuation, like for
instance with :
var sqM1 = function (x) { return 1 - x*x ;}
and you use sqM1(rotSpeedAtenuation) to multiply to current speed.