Page MenuHome

Incorrect angle measure with calc_edge_angle (bmesh vertex)
Closed, ResolvedPublic

Description

Blender Version
Tested with Blender 2.79 (official)
2017-09-11, Hash: 5bd8ac, Windows 64 build

Short description of error


Calling calc_edge_angle on a vert with 2 edges returns the supplement of the angle between the 2 edges instead of the interior or exterior angle as method description indicates.

calc_edge_angle(fallback=None)
.. method:: calc_edge_angle(fallback=None)
Return the angle between this vert's two connected edges.
:arg fallback: return this when the vert doesn't have 2 edges
   (instead of raising a :exc:`ValueError`).
:type fallback: any
:return: Angle between edges in radians.
:rtype: float

I suspect the problem looks to be with "bmesh_queries.c" on line 1753
blender\source\blender\bmesh\intern\bmesh_queries.c

return (float)M_PI - angle_v3v3v3(v1->co, v->co, v2->co);

Exact steps for others to reproduce the error
Create a mesh that has a vertex with 2 angles that are more or less than 90 degrees apart from one another. Enter edit mode and use Python API to call calc_edge_angle() on the vert.

TL:DR
Run script inside the attached blend file:

Additional notes
The calc_edge_angle() documentation states the method requires vert's with two connected edges." but this method will also work on vertices only attached to 1 edge (returns pi). Possible missed test case?

Also, on vertices with no edges or more than 2 edges the method throws this error message:

ValueError: BMVert.calc_edge_angle(): vert doesn't use 2 edges

I would suggest slightly different wording for error message to indicate exclusivity if 2 edges are required, eg:
"Method only works on vert with 2 edges"

Event Timeline

Improved the exception message, otherwise this isn't a bug.

if vertex between two edges makes a straight line, then the angle is zero.

The other issue noted in the image you posed - is just the result of rounding.

So to clarify, these 2 results were intended?

  1. Having the supplementary angle (assuming degree measure: 180 - angle_measure) instead of returning the "interior" angle.
  2. Having calc_edge_angle not raise an error when called with a vertex that has only 1 edge and instead return pi (~3.14).

I would suggest mentioning (2) in the method description if it was intended, e.g.

Return the angle between this vert's two connected edges.
Returns pi if this vert has only 1 edge.

The image was just to show the discrepancy between what I thought would have been the return value (~98.59 as shown in the 3D viewport) and the actual return value (~81.41) and that the returned angle was a supplementary angle.
I understood that 81.41 would be the result of rounding ~81.408929 :D