I implemented the \"bearing\" formula from http://www.movable-type.co.uk/scripts/latlong.html. But it seems highly inaccurate - I suspect some mistakes in my implementation.
You just have your parentheses () in the wrong place.
You are adding degrees to a value in radians, which won't work. toDegrees() will do the conversion from radians to degrees for you, then you do the normalisation once you have a value in degrees.
You have:
Math.toDegrees( (Math.atan2(y, x))+360 ) % 360;
But you need:
( Math.toDegrees(Math.atan2(y, x)) + 360 ) % 360;
Remember also that all inputs to Math.sin(), Math.cos() and all the other trigonometric functions must be in radians. If your inputs are degrees you'll need to convert them using Math.toRadians() first.