I think the computation for the tangent is OK, but I'm not sure about the rotation. As the surface area of the top of the polygon gets smaller, the tangent will get closer to the tangent plane normal. Event if they aren't the same, I think you want to rotate about the wall normal, not the tangent plane normal.