Andy-H Posted August 22, 2011 Share Posted August 22, 2011 Hi, what I want to do is select a point on an image and calculate that point after incremental rotations of 1 degree until the image has done a full 360 rotation. This if for custom markers for google maps but I havent got a clue where to start. I did find some information from another popular coding help forum but don't want to post it here because of advertising but basically it said: Yep, fairly. To map the point (x1,y1) via rotation around the origin: x2 = cos(a) * x1 + sin(a) * y1; y2 = cos(a) * y1 - sin(a) * x1; ... so you just first need to translate to the origin i.e. (-50,-50) in your example and translate back after rotation. x2 = cos(a) * (x1 - 50) + sin(a) * (y1 - 50) + 50; y2 = cos(a) * (y1 - 50) - sin(a) * (x1 - 50) + 50; ... Or something like that. (You can generate a matrix which will do all three transformations, I'll leave that for another answer or as an exercise...) But I have no clue what the guy is talking about lol Any help appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/245416-need-help-tracking-pixel-location-with-gd-imagerotate/ Share on other sites More sharing options...
btherl Posted August 23, 2011 Share Posted August 23, 2011 Which parts of that do you understand? Eg do you know how cos and sin work? Also are you rotating around (0,0) or are you rotating around an arbitrary point such as (50,50)? Such as when an image is indexed from 0-100 on each axis and you want to rotate around the center of the image? Quote Link to comment https://forums.phpfreaks.com/topic/245416-need-help-tracking-pixel-location-with-gd-imagerotate/#findComment-1260794 Share on other sites More sharing options...
Andy-H Posted August 24, 2011 Author Share Posted August 24, 2011 Its ok, I figured it out using these and setting a radius, function getPoints($deg, $rad, $offsetx, $offsety) { $x = round(cos($deg * M_PI / 180) * $rad) + $offsetx; $y = round(sin($deg * M_PI / 180) * $rad) + $offsety; return array('x' => $x, 'y' => $y); } function getCenter(&$im, $deg, $rad) { $cx = floor(imagesx($im) / 2); $cy = floor(imagesy($im) / 2); return getPoints(($deg - 90), $rad, $cx, $cy); } Cheers Quote Link to comment https://forums.phpfreaks.com/topic/245416-need-help-tracking-pixel-location-with-gd-imagerotate/#findComment-1261413 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.