Forceflow / trimesh2

C++ library and set of utilities for input, output, and basic manipulation of 3D triangle meshes
GNU General Public License v2.0
307 stars 72 forks source link

TriMesh::cornerangle uses incorrect formula for angle from known dot-product. #20

Open terraformist opened 1 year ago

terraformist commented 1 year ago

according to a formula for dot product: a_vec dot b_vec = a_mod b_mod cos(angle_a_b)

TriMesh::cornerangle misses a_mod * b_mod and the code should be:

inline float cornerangle(int i, int j) { using namespace ::std;

if (unlikely(faces.empty())) need_faces();
const point &p0 = vertices[faces[i][j]];
const point &p1 = vertices[faces[i][NEXT_MOD3(j)]];
const point &p2 = vertices[faces[i][PREV_MOD3(j)]];

// new lines down from here const point &v1 = p1 - p0; const point &v2 = p2 - p0; const float m = len(v1) * len(v2); // return line is replaced return acos(v1.dot(v2) / m); }

Forceflow commented 1 month ago

create a PR for this issue