# Help: how do I see the rotation value?

Discussion in 'iOS Programming' started by newbie80, Apr 28, 2011.

1. Apr 28, 2011
Last edited: Apr 29, 2011

### newbie80 macrumors member

Joined:
Mar 2, 2011
#1
Hi, I'm doing a rotation of an image. I want to know how do I see the rotation value when I rotate? Thank you.

Code:
```static inline CGFloat angleBetweenLinesInRadians(CGPoint line1Start, CGPoint line1End, CGPoint line2Start, CGPoint line2End) {

CGFloat a = line1End.x - line1Start.x;
CGFloat b = line1End.y - line1Start.y;
CGFloat c = line2End.x - line2Start.x;
CGFloat d = line2End.y - line2Start.y;

CGFloat line1Slope = (line1End.y - line1Start.y) / (line1End.x - line1Start.x);
CGFloat line2Slope = (line2End.y - line2Start.y) / (line2End.x - line2Start.x);

CGFloat degs = acosf(((a*c) + (b*d)) / ((sqrt(a*a + b*b)) * (sqrt(c*c + d*d))));

return (line2Slope > line1Slope) ? degs : -degs;
}
```
in my main file:
Code:
```- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

if ([touches count] == 2) {
NSArray *twoTouches = [touches allObjects];
UITouch *first = [twoTouches objectAtIndex:0];
UITouch *second = [twoTouches objectAtIndex:1];

CGFloat currentAngle = angleBetweenLinesInRadians([first previousLocationInView:self.view], [second previousLocationInView:self.view], [first locationInView:self.view], [second locationInView:self.view]);

label.transform = CGAffineTransformRotate(label.transform, currentAngle);
}
}
```
I tried to add this line to see the rotation value
Code:
```[statusRotate setText:[NSString stringWithFormat:@"%d",currentAngle]];
```
But the value sometimes changes to positive value or negative value, is currentAngle a radian?
How do I convert this value to degrees positive/negative value, or clockwise/counter clockwise degrees value? I'm kind of confuse now. Please help.

2. ### newbie80 thread starter macrumors member

Joined:
Mar 2, 2011
#2
Code:
```- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:self];

if ([self Intersecting:location :plans_shapea] && counterQ == 1) {

if ([touches count] == 2) {
NSArray *twoTouches = [touches allObjects];
UITouch *first = [twoTouches objectAtIndex:0];
UITouch *second = [twoTouches objectAtIndex:1];

CGFloat currentAngle = angleBetweenLinesInRadians([first previousLocationInView:self], [second previousLocationInView:self], [first locationInView:self], [second locationInView:self]);

plans_shapea.transform = CGAffineTransformRotate(plans_shapea.transform, currentAngle);

float currentAngle2;
currentAngle2 = currentAngle;
float degree = 0;
degree = currentAngle2 * (180/pi);

//[statusRotate setText:[NSString stringWithFormat:@"%d",currentAngle]];
[statusRotate setText:[NSString stringWithFormat:@"%d", degree]];
}

}
```
I added the following in above codes, but it looks like it doesn't show the positive or negative degrees value. It still show the radian value which sometimes show negative or positive, and not according to clockwise or anti clockwise.
Code:
```            float currentAngle2;
currentAngle2 = currentAngle;
float degree = 0;
degree = currentAngle2 * (180/pi);
```