Draw a line by passing a CGPoint object
<p>I have a problem while drawing a line by passing a <code>CGPoint</code> object through array. </p>

<p>At the time of <code>touchesBegan</code>, <code>touchesMoved</code> i add the CGPoint object in one array like this: </p>

<pre><code>    pointObject = [NSData dataWithBytes:&amp;lastPoint length:sizeof(CGPoint)];
    [drawingValueArray addObject:pointObject];
</code></pre>

<p>and it gives the normal drawing. </p>

<p>Next time i use this array pass this cgpoint value to the following code </p>

<pre><code>for (int i = 5; i&lt; [Array count] - 1 ; i++) {

        CGPoint pointYouWant = *(CGPoint*)[[Array objectAtIndex:i] bytes];
        point0 = point1;
        point1 = point2;
        point2 = point3;
        point3 = pointYouWant;
        if(point1.x &gt; -1){

           CGFloat redValue   =  [[undoActionArray objectAtIndex:0] floatValue];
            CGFloat greenValue =  [[undoActionArray objectAtIndex:1] floatValue];
            CGFloat blueValue  =  [[undoActionArray objectAtIndex:2] floatValue];
            CGFloat alphaValue =  [[undoActionArray objectAtIndex:3] floatValue];
            CGFloat penSize    =  [[undoActionArray objectAtIndex:4] floatValue];

        CGContextBeginPath(UIGraphicsGetCurrentContext());
        UIGraphicsBeginImageContext(drawingBoard.frame.size);
        [drawingBoard.image drawInRect:CGRectMake(0, 0, drawingBoard.frame.size.width, drawingBoard.frame.size.height)];
        CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), redValue, greenValue, blueValue, alphaValue);
        CGContextSetRGBFillColor(UIGraphicsGetCurrentContext(),redValue, greenValue, blueValue, alphaValue);
        CGContextSetLineWidth(UIGraphicsGetCurrentContext(),penSize);
        CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);

            double x0 = (point0.x &gt; -1) ? point0.x : point1.x; //after 4 touches we should have a back anchor point, if not, use the current anchor point
            double y0 = (point0.y &gt; -1) ? point0.y : point1.y; //after 4 touches we should have a back anchor point, if not, use the current anchor point
            double x1 = point1.x;
            double y1 = point1.y;
            double x2 = point2.x;
            double y2 = point2.y;
            double x3 = point3.x;
            double y3 = point3.y;
            // Assume we need to calculate the control
            // points between (x1,y1) and (x2,y2).
            // Then x0,y0 - the previous vertex,
            //      x3,y3 - the next one.

            double xc1 = (x0 + x1) / 2.0;
            double yc1 = (y0 + y1) / 2.0;
            double xc2 = (x1 + x2) / 2.0;
            double yc2 = (y1 + y2) / 2.0;
            double xc3 = (x2 + x3) / 2.0;
            double yc3 = (y2 + y3) / 2.0;

            double len1 = sqrt((x1-x0) * (x1-x0) + (y1-y0) * (y1-y0));
            double len2 = sqrt((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1));
            double len3 = sqrt((x3-x2) * (x3-x2) + (y3-y2) * (y3-y2));

            double k1 = len1 / (len1 + len2);
            double k2 = len2 / (len2 + len3);

            double xm1 = xc1 + (xc2 - xc1) * k1;
            double ym1 = yc1 + (yc2 - yc1) * k1;

            double xm2 = xc2 + (xc3 - xc2) * k2;
            double ym2 = yc2 + (yc3 - yc2) * k2;
            double smooth_value = 1.0;
            // Resulting control points. Here smooth_value is mentioned
            // above coefficient K whose value should be in range [0...1].
            float ctrl1_x = xm1 + (xc2 - xm1) * smooth_value + x1 - xm1;
            float ctrl1_y = ym1 + (yc2 - ym1) * smooth_value + y1 - ym1;

            float ctrl2_x = xm2 + (xc2 - xm2) * smooth_value + x2 - xm2;
            float ctrl2_y = ym2 + (yc2 - ym2) * smooth_value + y2 - ym2;

            CGContextMoveToPoint(UIGraphicsGetCurrentContext(), point1.x, point1.y);
            CGContextAddCurveToPoint(UIGraphicsGetCurrentContext(), ctrl1_x, ctrl1_y, ctrl2_x, ctrl2_y, point2.x, point2.y);

            CGContextStrokePath(UIGraphicsGetCurrentContext());
            drawingBoard.image = UIGraphicsGetImageFromCurrentImageContext();
            UIGraphicsEndImageContext();
}
</code></pre>

<p>This code joined the two ends of the line and created a closed shape and i don't want that.</p>

<p>i know i have done some mistake but i don't get it :(</p>

<p>Thank you.</p>
