Incorrect angle measure with calc_edge_angle (bmesh vertex) #53131

Closed
opened 2017-10-23 03:48:46 +02:00 by nBurn · 7 comments
Member

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

Short description of error
calc_edge_angle.png
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:
calc_edge_angle.blend

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"

**Blender Version** Tested with Blender 2.79 (official) 2017-09-11, Hash: 5bd8ac, Windows 64 build **Short description of error** ![calc_edge_angle.png](https://archive.blender.org/developer/F1059867/calc_edge_angle.png) 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](https://developer.blender.org/diffusion/B/browse/master/source/blender/bmesh/intern/bmesh_queries.c;6dfe4cbc6b8717223c631e80af6c7552576966e1$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: [calc_edge_angle.blend](https://archive.blender.org/developer/F1059869/calc_edge_angle.blend) **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*"
Author
Member

Changed status to: 'Open'

Changed status to: 'Open'
Author
Member

Added subscriber: @nBurn

Added subscriber: @nBurn
Campbell Barton was assigned by nBurn 2017-10-23 03:54:37 +02:00

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'

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.

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.
Author
Member

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

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

This issue was referenced by blender/blender@282af08fe2

This issue was referenced by blender/blender@282af08fe24890fb5231464bdbe8d0153467fc08

Changed status from 'Archived' to: 'Resolved'

Changed status from 'Archived' to: 'Resolved'
Sign in to join this conversation.
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#53131
No description provided.