I am trying to write a function to calculate the new x and y cooridinates after a rotation.
But for some reason it seems as though the sin function is not working as it should on a 180° angle:
$radians = deg2rad(180);
$sin = sin($radians);
The math functions use floating points. Because of the computational nature of floats, they have a few accuracy problems. The solution is to simply round your numbers:
$radians = deg2rad( 180 ); var_dump( $radians ); $sin = sin( $radians ); var_dump( round($sin, 3) );