I fixed the problem with the jerking. The problem was not only the use of var instead of double, I had also use radians instead of degrees.

I edited my first post with the improved code. Thanks for testing.