2
$\begingroup$

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

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

Manually:

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

It worked for me.

enter image description here

Python:

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

Since you modified your question:

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()[0][1].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[0].vertices[0]

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:

enter image description here

enter image description here

enter image description here

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):

enter image description here

$\endgroup$
  • $\begingroup$ 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 ? $\endgroup$ – Dante Jun 6 '17 at 23:27
  • $\begingroup$ @Dante just updated my answer to hopefully get you pointed in the right direction. $\endgroup$ – Rick Riggs Jun 7 '17 at 0:15
  • $\begingroup$ 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 $\endgroup$ – Dante Jun 7 '17 at 0:43
  • 1
    $\begingroup$ 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[0].co.x * e.verts[1].co.x + e.verts[0].co.y * e.verts[1].co.y + e.verts[0].co.z * e.verts[1].co.z a = math.sqrt(e.verts[0].co.x * e.verts[0].co.x + e.verts[0].co.y * e.verts[0].co.y + e.verts[0].co.z * e.verts[0].co.z) b = math.sqrt(e.verts[1].co.x * e.verts[1].co.x + e.verts[1].co.y * e.verts[1].co.y + e.verts[1].co.z * e.verts[1].co.z) rad = (a_b/a*b) deg = rad*180/3.14 angle = deg print(angle) $\endgroup$ – Dante Jun 7 '17 at 0:44
  • 1
    $\begingroup$ thank you very much finally it works , I will post the code $\endgroup$ – Dante Jun 7 '17 at 17:47
1
$\begingroup$
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[0].co - vert[1].co

v2 = vert[2].co - vert[1].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[0] * v2norm[0] + v1norm[1] * v2norm[1] + v1norm[2] * v2norm[2]

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.

enter image description here

for edge angle :

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

enter image description here

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Duane Dibbley Jun 7 '17 at 18:48
  • $\begingroup$ @DuaneDibbley Thank you , I wasn't aware of these functions. $\endgroup$ – Dante Jun 7 '17 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.