Artificial intelligent assistant

Midpoints of a recursively subdivided square I have a rectangle that I recursively subdivide along the horizontal and vertical axis in successiv order. The sides of the rectangle are both equal to one so the original midpoint is (x, y) = (0.5, 0.5). Dividing into a left and right rectangle along the vertical axis should yield two new rectangles with midpoints (0.25, 0.5), (0.75, 0.5). Dividing those along the horizontal should then yield (0.25, 0.25), (0.25, 0.75) for the left rectangle and (0.75, 0.25), (0.75, 0.75) for the right rectangle. My question is for the general case. Given that I know the midpoint of a rectangle how can I determine the midpoint of the two divided rectangles in the original rectangle for both the vertical and horizontal case?

You could model your operations as $$ \DeclareMathOperator{vsplit}{vsplit} \DeclareMathOperator{hsplit}{hsplit} \vsplit((x, y, w, h)) = ((x-w/4, y, w/2, h), (x + w/4, y, w/2, h)) \\\ \hsplit((x, y, w, h)) = ((x, y-h/4, w, h/2), (x, y+h/4, w, h/2)) $$ These functions take a rectangle, described as four tupel $(x,y,w,h)$ where $(x,y)$ are the coordinates of its midpoint, and return the rectangle tuples for the two children.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 34b8c95db29cf760cb607194c46b26a6