I am constructing wireframe model of 3d objects (prisms,..etc.). from a triangular mesh, I have obtained boundary points and fit striaght lines in order to get polygon edges refering to prism faces. Assume, I am having polygon edges as shown in green line segments. now I want to refine their positions. For example, If I take upper two planes (plane P1 and P2), then I am having two horizontal edges namely AB and CD. Elevation of these edges are h1 and h2 (h1 lessthan to h2). So I want to sweep the upper edge (i.e. AB edge) till it also has the same elevation as in CD (lower edge). In here, I should sweep the AB edge along the steepest gradient direction but on top of the P2 plane to come to A’B’ position.
please refer, figure to get a clear idea.

I want to implement this in C++ and still I am struggling to find a correct way to do it as my mathematics are so poor, so that, please someone help me by given equations to do this. then i can implement in c++ Thank you