As you probably have figured by now, this requires a bit of high school geometry with SIN and COS to manipulate the table around the Z-axis.
To put your XY touch coordinates back into the 3D domain will need the inverse functions - and likely some scaling as well.