import pymel.core as pm
def place_correct_pole_locator(joint1, joint2, joint3):
joint_start_position = pm.xform(joint1, q = 1, ws = 1, rp = 1)
joint_mid_position = pm.xform(joint2, q = 1, ws = 1, rp = 1)
joint_end_position = pm.xform(joint3, q = 1, ws = 1, rp = 1)
joint_start_vector = pm.dt.Vector(joint_start_position)
joint_mid_vector = pm.dt.Vector(joint_mid_position)
joint_end_vector = pm.dt.Vector(joint_end_position)
start_end_vector = joint_end_vector - joint_start_vector
start_mid_vector = joint_mid_vector - joint_start_vector
dotP = start_mid_vector.dot(start_end_vector)
proj = float(dotP)/float(start_end_vector.length())
start_end_normal = start_end_vector.normal()
proj_vector = start_end_normal*proj
arrow_vector = start_mid_vector - proj_vector
arrow_vector *= 2
final_vector = arrow_vector + joint_mid_vector
locator = pm.spaceLocator()
locator.t.set(final_vector)
if __name__ == '__main__':
JOINT_start = 'joint1'
JOINT_mid = 'joint2'
JOINT_end = 'joint3'
place_correct_pole_locator(JOINT_start, JOINT_mid, JOINT_end)
这个问题困扰我挺长时间,不是问题自身有多难,而是对矢量的运算没搞明白,好吧,说白了,是高中数学没学好,下面是自己最后实现的方式: