Can someone explain how this switched circuit charges and discharges the capacitor?
Closing the switch drops the voltage above R3 causing the voltage across it and the cap C1 to drop to zero, when the switch opens the cap begins charging again. The resistor R3 simply limits the current that can flow in and out of the capacitor for a slower discharge/charge.

The R1 and R2 form a resistive divider to divide the voltage of V1 at point D, but R1 also limits the current from the source when the switch is closed so it's not a direct short across the source when the switch is closed