This code should be moved into ObjectGenerator, and you can convert to and from a Vector3d. I think set_pvelocity also could be simplified with the new logic.