Well, there were problems in my trigonometry functions. But I spent a lot of time hunting bugs in them that weren't there. It turns out the real bug was in my tree algorithm: I wasn't backtracking correctly.
However, this now works, and you may play with it if you wish.

A similar tree, rooted in a nest of polygons of different numbers of sides, each in a different colour.

A deeply recursive, and rather schematic, drawing of a tree.