Skip to content

Instantly share code, notes, and snippets.

@serguei-k
Last active May 4, 2018 08:03
Show Gist options
  • Save serguei-k/71495d0f881739dea82a9ec0e70d270f to your computer and use it in GitHub Desktop.
Save serguei-k/71495d0f881739dea82a9ec0e70d270f to your computer and use it in GitHub Desktop.
Spherical Coordinates Stereographic Projection Inverse
import maya.api.OpenMaya as om
from math import *
def T(z):
return 0.5 * z
for i, p in enumerate(cmds.ls('unit.vtx[*]', fl=True)):
x, y, z = cmds.xform(p, q=True, t=True)
x = T(x)
y = T(y)
xprime = 2 * x / (1 + pow(x, 2) + pow(y, 2))
yprime = 2 * y / (1 + pow(x, 2) + pow(y, 2))
zprime = (-1 + pow(x, 2) + pow(y, 2)) / (1 + pow(x, 2) + pow(y, 2))
proj = om.MVector(xprime, yprime, zprime)
cmds.xform('unit.vtx[{0}]'.format(i), t=proj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment