Hi all!

With the help of some more math-inclined friends, I was able to script up a way to find the correct pole vector position in Maya.

Solving the problem required a little linear algebra and lots of simplification. Follow my script comments for a walk through of what I did.

Here’s the script:

import maya.cmds as cmds
"""
Finding pole vector position D given points A B and C
1. Find vectorAB and vectorAC
2. 0 = (vAC-vAB(k))(vAB)
3. k= ((vABx*vACx) + (vABy*vACy) +(vABz*vACz)) / (vABx^2 +vABy^2 + vABz^2)
4. Find the difference between vectorAC and vectorAK. That's the normal vector of plane ABC.
5. The location of point K is point A plus vectorAK
6. The location of point D is point C plus the normal vector. You can always scale the normal vector if that's too small or large a distance.
"""
def findPoleVector(objectA,objectB,objectC):
# our three given points
A = cmds.xform(objectA,q=1,t=1,ws=1)
B = cmds.xform(objectB,q=1,t=1,ws=1)
C = cmds.xform(objectC,q=1,t=1,ws=1)
# find vectorAB and vectorAC
vecAB = [B[0]-A[0],B[1]-A[1],B[2]-A[2]]
vecAC = [C[0]-A[0],C[1]-A[1],C[2]-A[2]]
# find K, which is the scalar (constant) for vectorAB that will give us the point where vector KC is perpendicular to vectorAB
# the equation for that is: k=(vecABx*vecACx + vecABy*vecACy + vecABz*vecABz)/(vecABx^2,vecABy^2,vecABz^2)
# we need to use float division in this case to find K or else Python will return 0
k = float(((vecAB[0]*vecAC[0]) + (vecAB[1]*vecAC[1]) + (vecAB[2]*vecAC[2]))) / float((vecAB[0]*vecAB[0] + vecAB[1]*vecAB[1] + vecAB[2]*vecAB[2]))
# now use k to find vector AK, which we will use later on to find where K is
vecAK = [vecAB[0]*k,vecAB[1]*k,vecAB[2]*k]
# use vectorAK to find the normal vector of the plane, which is found by subtracting vecAC from vecAK
nVector = [vecAC[0]-vecAK[0],vecAC[1]-vecAK[1],vecAC[2]-vecAK[2]]
# find point D by taking the nVector (like a 3d slope) from point C
D = [C[0] + .5*nVector[0],C[1] + .5*nVector[1],C[2] + .5*nVector[2]]
# do the same thing we did for point D, now with point K
K = [A[0] + vecAK[0],A[1] + vecAK[1],A[2] + vecAK[2]]
# done!
# these are just visual markers that are in the location of the points we calculated
dLoc = cmds.spaceLocator(n="D")
kLoc = cmds.spaceLocator(n="K")
cmds.xform(kLoc,t=K)
cmds.xform(dLoc,t=D)
print "A possible pole vector location is: " + str(D)
print "The normal vector is equal to: " + str(nVector)
return D
findPoleVector("A","B","C")

### Like this:

Like Loading...