Rotate Angle Smoothly To Point

68 Views Asked by At

I am trying to take angle A and smoothly rotate that angle towards angle B at a speed of S where the speed decreases with the distance between angle A and B. While angle A also turns via the shortest path to angle B.

A script I was given as a model for this:

Function: rotate_to_destination( A , B , S ); return ( A + ( sin( ( B - A ) * ( pi / 180 ) ) * S ) ); I've been using this and it works great except for a single problem: the time it takes for A to turn to B is lengthened significantly when the distance between A and B is exactly 180.

I'm not much for math so I haven't be able to fix the problem or cleverly come up with my own. Nor have I found another solution.

1

There are 1 best solutions below

1
On

Hint: $\sin(180°)=0!\;$ You are lucky that $\sin(\pi)$ is not exactly evaluated as zero in your script, otherwise the time would be infinite. A solution would be, to test the absolute value of $\sin((B-A) \cdot\pi / 180 )$ and use a minimum increment if it is below a certain threshold.