sphere sampling code