# Get the angle of an edge

I need to know the angle of an edge using bpy. I need this angle in the x-y plane so if the edge is aligned with the Y axis the angle will be 1.57 radiants (90 degree) and if the edge is aligned with the X axis the angle will be 0. Thanks

import bpy
from mathutils import *
from math import *

v1 = Vector([3,2,0])
v2 = Vector([3,2,1])
C = v2-v1

theta = atan2(C[1], C[0])

print(theta)


If you need to be able to compute this from the currently selected edge of a mesh, let me know and I can upgrade the python.

• With v1 = Vector([1,1,0]) and v2 = Vector([2,2,0]) should give me 0.78 rad (45°) but give me back 0.0. Thanks anyway! – isar Jun 17 '15 at 20:51
• OK, i was thinking "from the XY plane" , not "in the XY plane", fixed. – Mutant Bob Jun 17 '15 at 20:59
• Thanks , I was also trying with angle(other, fallback) but the angle was always absolute. Your is a much better way. – isar Jun 17 '15 at 21:40