Hi! I'm working on the iPad app, In which I have to rotate a arrow in a circle by touch. But I'm facing problems in it. The problem is in the angle calculation to which the image must be rotate.
You can check it here . I have to rotate the big red arrow image around the circle. Can anybody help me, How to get the angle of the touched point. Currently I'm using the following code, I found it at somewhere in the net. But it didn't rotate the arrow to the touched place.
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *oneTouch = [touches anyObject];
CGPoint currentPoint = [oneTouch locationInView:imgCompass];
double current_angle = [self wheelAngleFromPoint:currentPoint];
imgNeedle.transform = CGAffineTransformMakeRotation( current_angle );
}
- (double) wheelAngleFromPoint:(CGPoint)location
{
double retAngle;
// subtract center of wheel
location.x -= (self.imgNeedle.bounds.size.width ) / 2.0;
location.y = (self.imgNeedle.bounds.size.height ) / 2.0 - location.y;
// normalize vector
double vector_length = sqrt(location.x*location.x + location.y*location.y);
location.x = location.x/vector_length;
location.y = location.y/vector_length;
retAngle = acos(location.y);
float offset = 0.28;
//if (location.x)
// offset = 0.28;
retAngle += offset;
if (location.x<0)
{
retAngle = -retAngle;
}
return retAngle;
}
Can anyone help me in correct angle calculation.
Thanks