# Finding the Correct Pole Vector Position

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-A,B-A,B-A]
vecAC = [C-A,C-A,C-A]

# 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*vecAC) + (vecAB*vecAC) + (vecAB*vecAC))) / float((vecAB*vecAB + vecAB*vecAB + vecAB*vecAB))
# now use k to find vector AK, which we will use later on to find where K is
vecAK = [vecAB*k,vecAB*k,vecAB*k]
# use vectorAK to find the normal vector of the plane, which is found by subtracting vecAC from vecAK
nVector = [vecAC-vecAK,vecAC-vecAK,vecAC-vecAK]

# find point D by taking the nVector (like a 3d slope) from point C
D = [C + .5*nVector,C + .5*nVector,C + .5*nVector]
# do the same thing we did for point D, now with point K
K = [A + vecAK,A + vecAK,A + vecAK]

# 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")
```