# Access Bone Coordinates using Python API

I'm trying to export bone coordinates using ob.find_armature().data.bones.

I made a test file that has two connected bones, and set these position values manually in the UI.

Bone 1 Coordinates

• Head: (1, 1, 1)
• Tail: (2, 2, 2)

Bone 2 Coordinates (connected to Bone 1)

• Head: (2, 2, 2)
• Tail: (3, 3, 3)

So I go to access the bone data in python, and here's what I get.

Bone 1 Coordinates

• Head: (1, 1, 1)
• Tail: (2, 2, 2)
• I guess these are absolute world coordinates.

Bone 2 Coordinates (connected to Bone 1)

• Head: (0, 0, 0) These must be relative to the last bone's tail.
• Tail: (-0.00000, 1.732051, 0.000000) What are these?

Proof and test Blend file: https://app.box.com/s/olb6hzi3p0z4ejqbtyfk

• Figured out that head_local and tail_local will give me the coordinates I'm looking for, but I wish someone could explain what those other coordinates are. – winduptoy Nov 7 '14 at 6:52

API docs:

head - Location of head end of the bone relative to its parent

head_local - Location of head end of the bone relative to armature

tail - Location of tail end of the bone

tail_local - Location of tail end of the bone relative to armature

Since Bone 1 has no parent, the vector between object origin and bone head is used.

Bone 2's head it at Bone 1's tail (Connected is ticked), thus Bone 2's head is at (0, 0, 0) because there is no distance between both.

Bone 2's tail is at (0, 1.732, 0) because it's given relative to its parent bone. Bone 1 and 2 face the very same direction, all it takes is the length of the bone to define its endpoint (Bone direction is on the Y-axis in Blender). Tail minus head is

(3, 3, 3) - (2, 2, 2) = (1, 1, 1)


and the length

sqrt(12 + 12 + 12) = ~1.732
• How would I go about calculating an absolute location based on that tail vector? – winduptoy Nov 16 '14 at 22:51
• Should be ob.matrix_world * bone.tail_local. Not sure how to do that for bone.tail, likely involved some fancy matrix math. – CodeManX Nov 17 '14 at 0:25