I am creating a database for my local photos with a web interface, where I want to be able tag images and rotate them, amongst other things. When implementing tags (just like Facebook's tagging system) I have come across a problematic area. Namely:
Let's say I have tagged an image of (not) me:
And when I have rotated it, I want the tag coordinates to rotate with the image, like so:
Here is my problem. I store the coordinates in the database (x, y) in the CSS coordinate system, ie left/top instead of the mathematical left/bottom. (It might not be too big of an issue?)
The next big issue is that when I rotate around the center (the point [0,0]) I get negative coordinates. From, for example, [100, 100] to [-100, -100]. This is not correct because when I rotate an image, I don't get negative coordinates. The coordinate system is only positive.
All my rotation code has been using the vector rotation formula:
$nx = $x * cos(deg2rad($rotation_angle)) - $y * sin(deg2rad($rotation_angle));
$ny = $x * sin(deg2rad($rotation_angle)) + $y * cos(deg2rad($rotation_angle));
My question is: How do I solve this? I have tried just using abs
to turn the negative values to positive, but it results in the wrong coordinates.