I am aware that this question has been asked here: Removing unnecessary vertices?.
I want to focus a different point. How to remove unnecessary vertices without changing the shape at all. As you can see in the example below I want to get rid of vertex 2 and 3. All generalize or smooth functions I saw so far, will somehow alter the shape of the polygon/polyline. So they will mess with vertex 5,6 and 7 in the example.