im assuming the hat is a cylinder and the ball is a sphere
volume of cylinder (hat) = pi r^2 h
volume of sphere = 4/3 pi r^3
plug in your radius to first find volume of sphere
4/3 pi 3^3 = 36pi
set that equal to the formula for cylinder and solve
36pi = pi 3^2 h
36pi = 9pi * h
36pi / 9 pi = h
4=h