## Generative 3D structure; compound rotation/translation

Hello,

This is a bit more of a conceptual/mathsy problem than a technical one, but I am working in Flash CS4 and I thought this would be a good place to ask.

What I'm trying to do, essentially, is generate a 3D structure of square panels (subclassed sprites), connected perpendicularly at their edges. There are two connection parameters I'm planning to allow (and pick randomly between these on generation):
1. connecting edge:- top; bottom; left; or right
2. joining angle:- outer (where the connecting panel points away from the previous one; 270 degrees from the front); and inner (where the connecting panel points towards the screen from the previous one; 90 degrees from the front).

Defining where the subsequent panel should be placed from the initial one is quite straightforward. As an example, if the first panel is facing front on the stage, and the next connecting panel is selected to make a left-outer join, then (assuming panels have a registration point in the centre) that new panel should have the following transformations applied after being placed on top of the original:
• Add 90 to the .rotationY property (so it faces the left of the stage)
• Subtract half the panel's width from the .x property (so that it moves left to the edge of the first panel)
• Add half the panel's width to the .z property (so that its rightmost edge touches the leftmost edge of the original panel, perpendicularly)

I can quite easily define 8 transformation patterns like that for my 8 combined joining types, and use Math.random with Math.floor to pick one from an array. The problem I then have is that those defined transformations are relative to the starting point of the first panel, and so I can't use them repeatedly from their original state. Once the subsequent panels have been rotated, the set of 8 no longer apply.

So! I imagine related problems have been tackled before, and I was hoping for some general advice - not a free solution to the problem. If you know of any reading I could do on combining the 3D transformations in this way, that would be really helpful. I just don't know where to start!