I have been trying to get the Euler angles to each axis of a face normal vector but I haven't been successful so far. I tried using the direction cosines for each axis, but I haven't been successful as the returned value was completely off. Here's my code so far, I'm pretty sure there's a problem with my logic, specially in my math, but I cant really figure it out. I'm using python and the Maya for this. I'm modifying the manipulator pivot to check if the result. Thanks In advance! Here's my code:
import maya.cmds as cmds
import math as math
def Difference(a,b):
return list(set(a)- set(b))
def VertPosition(vert, axis):
return cmds.xform(vert,q = 1,ws = 1, t = 1)[axis]
def GetFaceNormal(face):
cmds.select(face,r=1)
faceNormal = cmds.polyInfo(fn=True)
return faceNormal
def GetNumericNormalValue(normalInfoString):
faceNormalDirection = [0,0,0]
normalInfoString = str(normalInfoString).split(' ')
faceNormalDirection[0] = float(normalInfoString[-3])
faceNormalDirection[1] = float(normalInfoString[-2])
faceNormalDirection[2] = float(normalInfoString[-1][:-5])
return faceNormalDirection
def NormalizeVector(vector):
vLength = VLength(vector)
for axis in range(0,3):
vector[axis] = vector[axis]/vLength
return vector
def VLength(vector):
vLength = 0
for axis in range(0,3):
vLength += pow(vector[axis],2)
vLength = math.sqrt(vLength)
return vLength
def GetAngleToAxis(vector):
vLength = VLength(vector)
angleToAxis = [0,0,0]
for axis in range(0,3):
angleToAxis[axis] += math.degrees(math.acos(vector[axis]/vLength))
return angleToAxis
faceSelection = cmds.filterExpand(sm=34)
normal = GetNumericNormalValue(GetFaceNormal(faceSelection))
normal = NormalizeVector(normal)
normalAngles=GetAngleToAxis(normal)
cmds.manipPivot(o=normalAngles)