hi there!
i'm stuck with a seemingly simple problem in mathematics: i need to rotate points in a 2-dimensional cartesian coordinate system, i.e. i have a point given by (x/y) and an angle gamma and i need to get the coordinates of this point if rotated by gamma...
example: if x = 2 and y = 0 and the angle of rotation is 90°, the resulting point would be x' = 0, y' = -2 (rotated clockwise)
so i found this formula on the net (http://en.wikipedia.org/wiki/Rotation_matrix) and implemented some code to test it:
$x = 1; echo "x: " . $x . "<br>";
$y = 1; echo "y: " . $y . "<br>";
$gamma = 45; echo "gamma: " . $gamma . "<br>";
$sinGamma = sin(deg2rad($gamma));
$cosGamma = cos(deg2rad($gamma));
$x2 = $x*$cosGamma - $y*$sinGamma; echo "x2: " . $x2 . "<br>";
$y2 = $y*$cosGamma + $x*$sinGamma; echo "y2: " . $y2 . "<br>";
while this works just GREAT for angles of 90/180/270 degrees, anything else would result in total crap!
i.e.:
if x=1 and y=1 and gamma=45°, the resulting point would lay exactly on the x-axis... well - the script above would output:
x: 1
y: 1
gamma: 45
x2: 1.11022302463E-16
y2: 1.41421356237
did i understand sth wrong? (school's over a long time for me ^^) how do i get this right?