Jump to content

Need help tracking pixel location with GD imagerotate


Andy-H

Recommended Posts

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.