mikedh / trimesh

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

Computing the difference along an axis between two meshes #2289

Open swiss-knight opened 2 months ago

swiss-knight commented 2 months 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 2 months 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.