Pinning is fairly straightforward. Given two objects, A and B, the pinned position of B on A at distance Dist through the angle Angle is found through the following two equations:
B.X = A.X + cos(A.Angle + Angle) * Dist
B.Y = A.Y + sin(A.Angle + Angle) * Dist
Setting Angle equal to 180 would place object B "behind" object A assuming that the image for object A is facing to the right.