mikedh / trimesh

Python library for loading and using triangular meshes.
https://trimesh.org
MIT License
3k stars 581 forks source link

Computing the difference along an axis between two meshes #2289

Open swiss-knight opened 1 month ago

swiss-knight commented 1 month ago

Hello,

Given two meshes files (*.PLY), how could I compare, i.e. compute the difference along the Z-axis between those 2 meshes?

Both meshes are representing terrain, so all triangles have an upward facing z-component (i.e. there is no overhang).

Individual triangles of each meshes are not aligned (i.e. they do not share (x,y) coordinates).

I am currently using trimesh version 4.4.9 with Python 3.12.6.

Thank you!

Warm Regards.

Kiord commented 1 month ago

Hello,

The Z component of the mesh vertices is mesh.vertices[:, 2].

If the two meshes have the same topology and if they are already superimposed w.r.t. the X and Y coordinates, the difference can be made vertex-wise (mesh1.vertices[:, 2] - mesh2.vertices[:, 2]).

Else, the comparison is still possible by projecting the vertices of one mesh on the other, or by using the texture/uv space of the two meshes to make the comparison. I think it depends on the type of result that you are expecting.