from random to orto

i need to make a canvas that change the curve in A to the curve in B.

For the black polyline i attempt to find the intersection and the common point but sometimes they are not the same.

I tried to use the offset+ slide curve command to solve the green blue problem but it won't work too.

finaly i want to make that polyline orto.

I use the pull point command ( pulling them to a grid) but it wont work quite well.