iPhone wheel not running smoothly
<p>I am implementing a wheel for iPhone which should turn clockwise or anti-clockwise upon being dragged into that direction. Although it does this, there was some errors with smoothness. Sometimes it seems like it get confused regards which way it should turn. Any help please?</p>

<pre><code> -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    NSSet *allTouches = [event allTouches];

    int len = [allTouches count]-1;

    UITouch *touch =[[allTouches allObjects] objectAtIndex:len];
    CGPoint location = [touch locationInView:[self superview]];

    xfirst = location.x;
    xnext = xfirst;
    x = [NSNumber numberWithFloat:xfirst];
    yfirst = location.y;
    ynext = yfirst;
    y = [NSNumber numberWithFloat:yfirst];
    //NSLog(@"Touch began for wheel at %f and %f",xfirst, yfirst);
    //NSLog(@"Centre %f and %f",self.center.x, self.center.y);
}

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch =[[allTouches allObjects] objectAtIndex:len];
    CGPoint location = [touch locationInView:[self superview]];

    xlast = location.x;
    ylast = location.y;

//dy / dx (gradient)
    if (((ylast-yfirst)/(xlast-xfirst) &gt;= 0.3) || ((ylast-yfirst)/(xlast-xfirst) &lt;= -0.3))
    {

    int seg1 = [self detectSegment:xnext :ynext];
    int seg2 = [self detectSegment:xlast :ylast];
    bool direction = [self isClockWise:seg1 :seg2];
    lastDirection = direction;

    float theAngle = [self getAngle:self.center.x:self.center.y:xfirst:yfirst:xlast:ylast];

    theAngle = theAngle / 6; 

    if (direction == YES)
    {

    }
    else {

        theAngle = -1*theAngle;
    }

    theAngle += totalRadians;   
    float rads = 6.28318531;
    int divAm = 0;
    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    [formatter setMaximumFractionDigits:0];
    [formatter setRoundingMode: NSNumberFormatterRoundDown];

    float nm = theAngle/rads;
    NSString *numberString = [formatter stringFromNumber:[NSNumber numberWithFloat:nm]];
    [formatter release];
    divAm = [numberString floatValue];
    theAngle = theAngle - (float)(6.28318531*divAm);
    totalRadians = theAngle;
    xnext = xlast;
    ynext = ylast;
    [self rotateImage:theAngle];
    }
}


- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
}

-(float) getAngle: (CGFloat)P1x: (CGFloat)P1y: (CGFloat)P2x: (CGFloat)P2y: (CGFloat)P3x: (CGFloat)P3y {
    float P23 = [self getLength:P2x:P2y:P3x:P3y];
    float P12 = [self getLength:P1x:P1y:P2x:P2y];
    float P13 = [self getLength:P1x:P1y:P3x:P3y];
    return acos((P23*P23 - P12*P12 - P13*P13)/(-2*P12*P13));
}

-(float) getLength: (CGFloat)P1x: (CGFloat)P1y: (CGFloat)P2x: (CGFloat)P2y
{
    return sqrt((P1x-P2x)*(P1x-P2x) + (P1y-P2y)*(P1y-P2y));
}
</code></pre>

<p>Any suggestions please?</p>
