Constrained Diffusion: Applications to Image Generation, Manifold Learning, and Motion Planning