I want to implement a auto complete feature for a drawing app. Once a free hand object is drawn, I want to detect the type of object (circle/rectangle/triangle) and based on
You need to segment the data points first. Google on "stroke segmentation" to find related articles. One simple and fast algorithm is to compute the forward slope and backward slope for each data point, then compute the turning angle between forward slope and backward slope. If the turning angle is greater than a certain angle threshold, then you can assume that your path takes a sharp turn there. From the number of sharp turns computed, you can infer whether the points represent a triangle (with 2 sharp turns), a quadrilateral (with 3 sharp turns) or something else. To infer that the data points represent a circle or a rectangle, you will need to do additional computation. For example, if there is no sharp turns at all, do a circle fitting to the data points to see if the maximum error to the fitted circle is smaller than a certain tolerance. To output a rectangle, you will have to fit straight lines to each segment of data points and check if the fitted lines are more or less orthogonal to each other.
You can iterate through UIBezierPath
points with CGPathApply(..)
method. Look here for example.
But you should determine shape type somehow - it's mathematical task and approach depends on your input data.