I remember a colleague addressing this issue with the output of a stream digitizer
(using FORTRAN 77 with ArcInfo 4.03 object code, in 1988 [The more things change...]).
The "knots" could be removed by identifying the segments that changed direction
by nearly 180 degrees. You could speed up your solution (and make it handle multiple
occurances) by passing through the vertex list once, calculating the orientation of
segments from A to B ( atan2(By-Ay,Bx-Ax) ) and B to C ( tan2(Cy-By,Cx-Bx) ) and
looking for an absolute delta greater than 165-170 degrees. If you organize the loops
right, you'll only need to call atan2 nverts-1 times (sliding the A B C designations across
the length of the line). O(N) beats O(N^2) every time.
- V
PS: You should also look for coincident points (Cy-By == 0 && Cx-Bx == 0) while you're at it...