python 来自http://jinglezzz.tumblr.com/post/60149245050/calculating-the-angle-between-vectors-in-maya

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 来自http://jinglezzz.tumblr.com/post/60149245050/calculating-the-angle-between-vectors-in-maya 相关的知识,希望对你有一定的参考价值。


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')

以上是关于python 来自http://jinglezzz.tumblr.com/post/60149245050/calculating-the-angle-between-vectors-in-maya 的主要内容,如果未能解决你的问题,请参考以下文章

python 来自Python的Git pull

python 来自Python的os文件系统

一封来自“Python”的信

来自 Black Hat Python 书的 Python 嗅探

“路径 python3(来自 --python=python3)不存在”错误

python Python装饰模板(来自“Head First Python ed.2”)