There is no solution to your question the way you ask it.
Sergei is right when he says
Quote:
You are not ready to solve such problems, because you have no clue on how to define the problems.
First rule of programming: You have to master the problem well enough to explain the computer what to do. It is mandatory because the computer is fast but stupid, he will never guest something.
Advice: Try to solve the problem by hand.
Take a set of arbitrary polylines, some regular, others non regular.
Take a sqare, a rectangle, a cross, a triangle, a star, a pentagon, an hexagon, a horse shoe ... , and you can play with sizes.
Pick one shape and check it against the others graphically and choose the best one. repeat many time, until you have defined the rules for the best answer.
Your definition of best choice will make a new set of problems to solve.