There is a broken line defined as a set of points. I am trying to come up with an algorithm for inserting a new point into this curve. I just can't figure out how to determine the insertion position.
The first thought was to consider the triangles that the new point and the pair of existing neighboring points form, and choose the triangle with the smallest perimeter. However, for such a case
the algorithm considers it necessary to insert a new point between the first and second. Although the second and third are clearly better suited.
I also thought to consider the same triangles, and choose with the smallest height. But even here the algorithm will work incorrectly in certain situations. For example here 
the algorithm will choose a position between points 3 and 4, together 1 and 2.
To exclude such cases, I decided to consider only triangles with acute angles at the base. But here there were exceptions.
Both candidate triangles have obtuse angles at the base.
In general, I'm at a dead end. Surely this problem has some kind of solution, or at least a name that you can google. After all, people write all sorts of autocodes and the like.