# How to Set/Calculate pole angle of IK constraint so the chain does not move?

How to calculate the exact pole angle so when I add Pole bone the IK chain does not move? This is what the pole angle is: Its a signed angle between the Base_Bone's X axis and the projected Pole_axis onto Base_Bone's XZ plane. The direction of projection is IK_axis.

Fill in the bone names, it will print the appropriate pole angle into System console. Then you can set the IK constraint with that Pole bone and angle and the IK chain won't move:

import bpy
from mathutils import *

def signed_angle(vector_u, vector_v, normal):
# Normal specifies orientation
angle = vector_u.angle(vector_v)
if vector_u.cross(vector_v).angle(normal) < 1:
angle = -angle
return angle

def get_pole_angle(base_bone, ik_bone, pole_location):
return signed_angle(base_bone.x_axis, projected_pole_axis, base_bone.tail - base_bone.head)

base_bone = bpy.context.active_object.pose.bones["BASE_BONE_NAME"]
ik_bone = bpy.context.active_object.pose.bones["IK_BONE_NAME"]
pole_bone = bpy.context.active_object.pose.bones["POLE_BONE_NAME"]