trimesh2 icon indicating copy to clipboard operation
trimesh2 copied to clipboard

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

Open terraformist opened this issue 3 years ago • 1 comments

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); }

terraformist avatar Sep 21 '22 12:09 terraformist

create a PR for this issue

Forceflow avatar Jul 20 '24 12:07 Forceflow