# How to get angle of edge ? (python)

How can I get the angle of the edge , is there a method that return the angle of selected edge ?

• I'm not very good at maths but can't you compute it easily from its start and end point coordinates. – Duarte Farrajota Ramos Jun 7 '17 at 0:26
• @DuarteFarrajotaRamos I did that already many times , unfortunately I never got the correct angle. – Dante Jun 7 '17 at 2:18

Manually:

In edit mode, with your edges selected, fire up the properties panel N, and click on Edges, & Angle.

It worked for me. Python:

bpy.data.meshes["Plane"].show_edges
bpy.data.meshes["Plane"].show_extra_edge_angle


## Here is an append to this answer that may get you closer:

To Actually access the information that you need, you could get all the verts and calculate angle based on XYZ deltas:

bpy.data.meshes['Plane'].vertices.items().co

I'm not going to solve it for you, but I will at least tell you how I would approach it.

I would first loop through the verts using something like:

for vert in bpy.data.meshes['Plane'].vertices: print(str(vert.co.x) + "," + str(vert.co.y) + "," + str(vert.co.z))

Note this is just printing the coordinates of each vert (not very useful, other than showing you how to access their info).

Then I would calculate the angle between each vert, find the selected edges that match these verts, and spit out the angle.

Please note that you can access .edges similarly to .vertices, inside of the .edges object you will have a vertices object that is a list of two vertex indices:

eg. py.data.meshes['Plane'].edges.vertices

It seems doable, just have to figure out the calculations, and how you are going to narrow down your selection.

Hope it helps.

I think that you would have an easier time if you thought about doing the calculations after you account for coordinate system rotations in the following example case I'm simplifying this to only "Z"

Here is a visual circular example to show you what I mean:   From your comment it seems that you are not taking this into account.

It is advisable to calculate the midpoints of the section, and do your calculations from there, because as you see in the circular example on side of the mesh is longer than the other, and getting the midsection helps you to work on the average edge rotation.

Once you have this, you can translate your coordinate locations to rotate about "Z" via the indicated angle.

As another hint, it may be advantageous to think about this angle according to the following (Where I believe that your desired angle is the sum of a2 & a3): • sorry if my question was not clear , I want to get the value of the angle to use it for example : angle = edge.get_angle() if angle > 50: do something is there a method that return the angle of the edge ? – Dante Jun 6 '17 at 23:27
• @Dante just updated my answer to hopefully get you pointed in the right direction. – Rick Riggs Jun 7 '17 at 0:15
• thanks for the answer , I tried many ways but still can't get the displayed angle correctly :( while the angle for the selected edge is Zero when i run this code it give me 35.98 – Dante Jun 7 '17 at 0:43
• import bpy,bmesh import math obj = bpy.context.object.data bmsh = bmesh.from_edit_mesh(obj) for e in bmsh.edges: if e.select: a_b = e.verts.co.x * e.verts.co.x + e.verts.co.y * e.verts.co.y + e.verts.co.z * e.verts.co.z a = math.sqrt(e.verts.co.x * e.verts.co.x + e.verts.co.y * e.verts.co.y + e.verts.co.z * e.verts.co.z) b = math.sqrt(e.verts.co.x * e.verts.co.x + e.verts.co.y * e.verts.co.y + e.verts.co.z * e.verts.co.z) rad = (a_b/a*b) deg = rad*180/3.14 angle = deg print(angle) – Dante Jun 7 '17 at 0:44
• thank you very much finally it works , I will post the code – Dante Jun 7 '17 at 17:47
import bpy
import math
import bmesh

vert = []

obj = bpy.context.object.data

bmsh = bmesh.from_edit_mesh(obj)

for elem in reversed(bmsh.select_history):
if isinstance(elem, bmesh.types.BMVert):
vert.append(elem)

v1 = vert.co - vert.co

v2 = vert.co - vert.co

v1mag = math.sqrt(v1.x * v1.x + v1.y * v1.y + v1.z * v1.z)

v1norm = [v1.x/v1mag , v1.y/v1mag , v1.z/v1mag]

v2mag = math.sqrt(v2.x * v2.x + v2.y * v2.y + v2.z * v2.z)

v2norm = [v2.x/v2mag , v2.y/v2mag , v2.z/v2mag]

res = v1norm * v2norm + v1norm * v2norm + v1norm * v2norm

angle = (math.acos(res)*180/math.pi)

print(angle)

bmesh.update_edit_mesh(obj)


this code depend on the selection of three vertices , it will calculate the angle for the second selected vertex. for edge angle :

angle = (math.acos(res)*180/math.pi)-180 • The math module has predefined functions for converting between degrees and radians. math.degrees() converts an angle in radians to degrees, and math.radians() does the opposite. Apart from calrity I don't think there's any real advantage over doing the calculations like in your code, but it's not impossible that there's also better precision. – user27640 Jun 7 '17 at 18:48
• @DuaneDibbley Thank you , I wasn't aware of these functions. – Dante Jun 7 '17 at 19:22