>>> // Calculate compass heading >>> var compassHeading = Math.atan(Vx / Vy); >>>>>>
>class Test_atan > { > internal static void Go() > { > // 180 + 45= 225 degrees > double rads = Math.PI + Math.PI / 4.0; > > double sin = Math.Sin(rads); > double cos = Math.Cos(rads); > > double atanDegrees = RadianToDegree(Math.Atan(sin / cos)); > double atan2Degrees = RadianToDegree(Math.Atan2(sin, cos)); > > Console.WriteLine("{0} {1} ", atanDegrees, atan2Degrees); > > } > static double DegreeToRadian(double degrees) > { > return Math.PI * Modulo(degrees, 360.00) / 180.0; > > } > static double RadianToDegree(double rads) > { > return Modulo(rads, Math.PI * 2) * (180.0 / Math.PI); > } > static double Modulo(double dividend, double divisor) > { > return (dividend % divisor) > + (Math.Sign(dividend) * Math.Sign(divisor) >= 0 ? 0 : divisor); > } > } >Hmm. Firstly I screwed the atan2() function - I had Math.atan(Vx / Vy) instead of Math.atan2(Vx ,Vy).