我需要計算線條之間的角度。我需要計算atan。所以我用這樣的代碼有助於正確計算atan2
static inline CGFloat angleBetweenLinesInRadians2(CGPoint line1Start, CGPoint line1End)
{
CGFloat dx = 0, dy = 0;
dx = line1End.x - line1Start.x;
dy = line1End.y - line1Start.y;
NSLog(@"\ndx = %f\ndy = %f", dx, dy);
CGFloat rads = fabs(atan2(dy, dx));
return rads;
}
但我不能超過180度((後
179度去178..160..150等等。我需要在360度旋轉我怎麼能做到這一點有什麼不對
莫比這有助於:??
//Tells the receiver when one or more fingers associated with an event move within a view or window.
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSArray *Touches = [touches allObjects];
UITouch *first = [Touches objectAtIndex:0];
CGPoint b = [first previousLocationInView:[self imgView]]; //prewious position
CGPoint c = [first locationInView:[self imgView]]; //current position
CGFloat rad1 = angleBetweenLinesInRadians2(center, b); //first angel
CGFloat rad2 = angleBetweenLinesInRadians2(center, c); //second angel
CGFloat radAngle = fabs(rad2 - rad1); //angel between two lines
if (tempCount <= gradus)
{
[imgView setTransform: CGAffineTransformRotate([imgView transform], radAngle)];
tempCount += radAngle;
}
}
我嘗試了。不工作 – yozhik 2010-11-02 17:11:13
@yozhik:也許你應該去明白什麼是行不通的。預期的結果是什麼?你看到了什麼? – casablanca 2010-11-02 17:14:39
我有一個十進制座標系。我正在拍攝照片。有成像零。當我在180度以上拍攝並移動我的照片時 - 一切盡在掌握。當我試圖移動180度,例如190度時,它會顯示170度。我需要那裏190度。你看...... – yozhik 2010-11-02 17:24:49