I am trying to write some point / line detection software based on what a user is drawing on a canvas (I have been doing this all via the web and html 5 canvas). When a user performs a MouseDown event we create an array that will hold all of the points of his / her drawing. Each MouseMove event after that pushes a point (x, y) onto the array. The MouseUp event signals the end of the user's drawing. What I want to do with those points is determine where the user has distinctly changed directions. Take the following example:
The above methodology has generated the following ordered set of points:
[(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 4), (7, 3), (8, 2)]
So based on these points I can tell the user has distinctly changed directions at point (5, 5) onward. The outcome of the program would give me three points [(1, 1), (5, 5), (8, 2)] because I will use the first point of the sequence, try to find a distinct change in direction and get that point, and use the final point in the sequence.
The above example is extremely simplified because of the number of points and the fact that they are in a completely straight line. When a user is actually drawing on a canvas the line will not be completely straight. For my purposes you can assume the user is drawing straight-ish lines and not blatantly curved ones.
So based on the above information what algorithms, methodologies, etc would you suggest I use?
EDIT: typo
Say your points, in order are [(x1, y1), (x2, y2),..., (xn, yn)]. Compute approx derivatives between each consecutive set of points: D1 = (y2-y1)/(x2-x1), D2=(y3-y2)/(x3-x2), etc. Then watch for significant (lasting) changes in the derivative. In your case, D1=1, D2=1, D3=1, D4=1, D5=-1, D6=-1, D7=-1. Note that you have to be careful if they draw a vertical line because the division will be by zero in that case.