Check the picture below.
so, notice, we first use squarish base, to get the diagonal distance, then we use half that, for the triangle you see shaded above, to find the height "h" using the pythagorean theorem on each case.
on the bottom part of the picture, we use that "h" and since it's a square at the bottom, the distance from the center to a side is just 3, then we use the pythagorean theorem to get the slant height "sh".