Finding the angle from the center of the imag, Find degrees between the two locations
Ok.
I'm racking my brain on this one.
Onscreen I have an object (UIImageView) that I want to be able to rotate with my finger. Basically touch it and move my finger around and have it rotate on it's center to follow my finger.
Rotating the image is no big deal, I give it the radial that I want it to rotate on(0-360) and it aligns itself nicely.
CGAffineTransform imgObjectRot = CGAffineTransformMakeRotation(radians(90));
imgObject setTransform:imgObjectRot;
static inline float radians (double degrees) {
return degrees * M_PI/180;
}
My problem is when I incorporate the touch. I can't figure out a way of finding the angle from the center of the image to the touch location.
Should be a simple formula based on x1,y1 and x2,y2. In fact I found some examples but the math is pretty complicated - and the iPhone doesn't seem to have the built in math functions like ATAN.
Anyhow, there must be some easier / built in way that I'm missing.
I don't know if it makes sense to find the degrees between the two locations or if I can "attach" the touch location to the image object and follow it with some built in commands.
Any ideas?
|