Hello!
I have this strange issue with mesh surface area calculation. Surface area increases, if i "subdivide" mesh to be more detailed and add more polygons, even tho the relative size remains the same.
Code is rather simple and the formula itself doesn't matter as much as differentiating results based on polygon count.
float total_area = 0;
int indice_count = finalMeshIndices.length;
for (int i = 0; i < indice_count; i += 3)
{
float area = 0;
Vector3 p1 = new Vector3(finalMeshVertexFloatArray[i + 0], finalMeshVertexFloatArray[i + 1], finalMeshVertexFloatArray[i + 2]);
Vector3 p2 = new Vector3(finalMeshVertexFloatArray[i + 10], finalMeshVertexFloatArray[i + 11], finalMeshVertexFloatArray[i + 12]);
Vector3 p3 = new Vector3(finalMeshVertexFloatArray[i + 20], finalMeshVertexFloatArray[i + 21], finalMeshVertexFloatArray[i + 22]);
Vector3 e1 = p2.sub(p1);
Vector3 e2 = p3.sub(p1);
Vector3 e3 = e1.crs(e2);
area = (float) (0.5 * Math.sqrt(e3.x * e3.x + e3.y * e3.y + e3.z * e3.z));
if (Float.isNaN(area)) System.out.println("NaN... The fuck?");
total_area += area;
}
I think the issue is with float precision, because i have the same issue if i take a model and flip it.
Here is visual representation
If i take a cube 1,1,1 its area is ~5
If i upscale it 3 times, its area becomes ~19
So it seems that float precision is a culprit here. At least i guess so.