I solved my problem but still lack a solution? There is an offset appearing I was just checking the wrong axis. I noticed that there was an x offset of 0.6 and of course the y axis and z axis would not change as I rotate the parent object as the local coordinates move with the parent.

So where I was expecting the y and z axis to change values of course it will not because it is still locally at the same coordinates from the parent despite what angle of rotation the parent object is in.

The only way it works is if I take the world coordinates for the empty and the parent then do the calculations based on those values.

Just for info I am trying to do a Piston and crank animation without using bones using Pythagoras theorem to calculate positions but it needs to work so that if I move the whole train that everything still animates correctly.

seemed like a simple project at first but became rapidly complicated and the aim was to create a generic script that would work for multiple projects based on values input as parameters.

Though I am someone ‘THICK’ in the math department. Maybe this is currently beyond my capability.