There’s an example in the JOSM code: http://josm.eigenheimstrasse.de/browser/src/org/openstreetmap/josm/data/projection/Projection.java

A Google search offered some more hints, but the above JAVA code should point you in the right direction…