Functions in real life: Playing Ping Pong

What function is used to play this game?

How do I cause the motion? How did I restrict the area of movement? Can you create the same for tennis?