There are several solutions on the forum for computing plane aligned bounding boxes that might help. Here’s an example I wrote, implemented here to find the smallest area bounding box for a planar polyline in the XY plane:
220407_SmallestAlignedBoundingBox_00.gh (2.9 KB)
Also, it’s good the upload a file when posting. And welcome
Edit: Depending on requirements, these polyline “simplification” methods might also be relevant: