splinecraft
3/6/2017 - 7:23 PM

From http://jinglezzz.tumblr.com/post/60149245050/calculating-the-angle-between-vectors-in-maya measure angle of 3 joints


import pymel.core as pm
from math import acos, degrees, pow, sqrt

def getDistance(a,b):
    return sqrt(pow(a[0] - b[0], 2) + pow(a[1] - b[1],2) + pow(a[2] - b[2],2))
    
def getAngle(sideA,sideB,center):
        
    a_end = PyNode(sideA).t.get()
    b_end = PyNode(sideB).t.get()
    center = PyNode(center).t.get()
    
    hypotenuse = getDistance(a_end, b_end)
    opposite = getDistance(a_end, center)
    adjacent = getDistance(b_end, center)
    
    angleInRadians = acos((pow(adjacent,2) + pow(opposite,2) - pow(hypotenuse,2)) / (2.0 * opposite * hypotenuse))
    
    return degrees(angleInRadians)
    
print getAngle('joint_1', 'joint_2', 'joint_center')