0

I am trying to draw a figure without releasing finger and when I release finger I want to compare that shape to see if it's a line, a circle, a square or let's say a "Z".

I am kinda new to drawing and stuff like that so I have no idea how to make this.

I am drawing with following code:

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

    mouseSwiped = NO;
    UITouch *touch = [touches anyObject];
    lastPoint = [touch locationInView:self.view];
}

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

    mouseSwiped = YES;
    UITouch *touch = [touches anyObject];
    CGPoint currentPoint = [touch locationInView:self.view];

    UIGraphicsBeginImageContext(self.view.frame.size);
    [self.mainImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), brush );
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red, green, blue, 1.0);
    CGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeNormal);

    CGContextStrokePath(UIGraphicsGetCurrentContext());
    self.mainImage.image = UIGraphicsGetImageFromCurrentImageContext();
    [self.mainImage setAlpha:opacity];
    UIGraphicsEndImageContext();

    lastPoint = currentPoint;


//    [CGRect.testForCircle(, <#NSDate *firstTouchDate#>)]
}

My question is: How can I detect if what was draw it is a circle a square or a "Z"?

Ideas/Suggestions/Code are welcomed! Thank you!

Silviu St
  • 1,810
  • 3
  • 33
  • 42
  • Also see http://stackoverflow.com/questions/31370054/how-to-detect-users-freehand-drawing-to-primitive-geometrical-objects-like-squa – rmaddy Sep 08 '15 at 14:54
  • @rmaddy Sorry and Thank you! from your comment I've reached this http://fe9lix.github.io/DollarP_ObjC/ which does exactly what I needed – Silviu St Sep 08 '15 at 15:24

0 Answers0