Skip to content

Commit

Permalink
Use non-normalized normals in Mesh centroid
Browse files Browse the repository at this point in the history
  • Loading branch information
gselzer committed Jun 25, 2024
1 parent d9d1528 commit 73a0f41
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/main/java/net/imagej/ops/geom/CentroidMesh.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ public RealLocalizable calculate(final Mesh input) {
final long v0 = input.triangles().vertex0(i);
final long v1 = input.triangles().vertex1(i);
final long v2 = input.triangles().vertex2(i);
final double nx = input.triangles().nx(i);
final double ny = input.triangles().ny(i);
final double nz = input.triangles().nz(i);
final double v0x = input.vertices().x(v0);
final double v0y = input.vertices().y(v0);
final double v0z = input.vertices().z(v0);
Expand All @@ -82,6 +79,18 @@ public RealLocalizable calculate(final Mesh input) {
final double v2x = input.vertices().x(v2);
final double v2y = input.vertices().y(v2);
final double v2z = input.vertices().z(v2);

// Recompute (non-normalized) normals
final double ux = v1x - v0x;
final double uy = v1y - v0y;
final double uz = v1z - v0z;
final double vx = v2x - v0x;
final double vy = v2y - v0y;
final double vz = v2z - v0z;
final double nx = (uy * vz - uz * vy);
final double ny = -(ux * vz - uz * vx);
final double nz = (ux * vy - uy * vx);

c_x += (1 / 24d) * nx * (Math.pow((v0x + v1x), 2)
+ Math.pow((v1x + v2x), 2)
+ Math.pow((v2x + v0x), 2));
Expand All @@ -98,6 +107,6 @@ public RealLocalizable calculate(final Mesh input) {
c_y *= d;
c_z *= d;

return new RealPoint(-c_x, -c_y, -c_z);
return new RealPoint(c_x, c_y, c_z);
}
}

0 comments on commit 73a0f41

Please sign in to comment.