mikedh / trimesh

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

bounds.oriented_bounds failed for less than 3 points #2025

Open YuanWenqing opened 1 year ago

YuanWenqing commented 1 year ago

Try bounds.oriented_bounds(points) with only 2 points, thus error like:

...
  File ".../python3.7/site-packages/trimesh/bounds.py", line 220, in oriented_bounds
    return oriented_bounds_coplanar(points)
  File ".../python3.7/site-packages/trimesh/bounds.py", line 170, in oriented_bounds_coplanar
    if np.any(np.abs(points_2d[:, 2]) > coplanar_tol):
IndexError: index 2 is out of bounds for axis 1 with size 2

The reason is that points_2d generated by points_2d = np.matmul(points_demeaned, vh.T) has a shape (2,2).

Should we check point num before calling oriented_bounds or 2 points be accepted in this method?

mikedh commented 1 year ago

Yeah that should probably be checked, PR's welcome!