Space arranging

Hi all,

I have a series of 2D polylines and want to write a quick script that takes these lines and moves and rotates them in order to fit them into as small a space as possible.

I'm fairly new to MaxScript but do have experience in other programming languages. It is the idea of telling the objects not to cross as well as the idea of an invisible bounding box which calculates the minimum area that I'm getting confused by. Any help would be much appreciated....thanks