Getting the rotation of a face normal from the Axis
Question: 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)
    


Answer: There are a few ways to interpret the data but if given a vector you want the
respective rotations per major axis you take the inverse tangents of the
components of the vector. The choice of components determines the axis of
rotation:

    
    
    inVec = /(input vector)/
    rotZ = atan(inVec.y/inVec.x)
    rotY = atan(inVec.x/inVec.z)
    rotX = atan(inVec.y/inVec.z)
    

results are in radians.

