cr8zy1van Posted November 10, 2011 Share Posted November 10, 2011 I am trying to rotate a point around a fixed origin in the middle of an image (i need to do this for data in an array so i don't want to rotate the whole image) So far I have: function returnRotatedPoint($x,$y,$a){ $a = deg2rad($a); // convert to radians $ox = 100; // origin point - always fixed but may change (image size is 200x200) $oy = 100; $x = $ox + ( cos($a) * ($x - $ox) - sin($a) * ($y - $oy) ); $y = $oy + ( sin($a) * ($x - $ox) + cos($a) * ($y - $oy) ); return array("x"=>$x,"y"=>$y); } When I call it by in my code: $zpoint1 = returnRotatedPoint(10, 100, 50); echo $zpoint1["x"].",". $zpoint1["y"]; the data it is really wonky. I haven't been able to find a pattern yet. Anyone see something obvious that I am missing? I don't usually work in PHP and am sure it is probably just something I am doing wrong. Quote Link to comment https://forums.phpfreaks.com/topic/250898-simple-rotation-of-point-around-origin-question/ Share on other sites More sharing options...
cr8zy1van Posted November 11, 2011 Author Share Posted November 11, 2011 Nevermind... maybe I should go running more often and not try to overwrite x, while the next line needs x untouched. Fixed code below. Issue fixed... close this thread. function returnRotatedPoint($x,$y,$a){ $a = deg2rad($a); // convert to radians $ox = 100; // origin point - always fixed but may change $oy = 100; $xnew = $ox + ( cos($a) * ($x - $ox) - sin($a) * ($y - $oy) ); $ynew = $oy + ( sin($a) * ($x - $ox) + cos($a) * ($y - $oy) ); return array("x"=>$xnew,"y"=>$ynew); } Quote Link to comment https://forums.phpfreaks.com/topic/250898-simple-rotation-of-point-around-origin-question/#findComment-1287244 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.