question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bounding box corner question

See original GitHub issue

Hi Mike,

I came across your Trimesh library for Python after trialling several other tools for generating signed distance functions from STL files. I’ve found yours to be by far the best for what I need, but I have a simple question that I couldn’t quite figure out from looking at the source:

Essentially what I want to do is to fill the bounding box with a 3D rectangular grid of points, and compute the SDF from these. I am able to generate points and calculate the SDF with no problems, but I don’t know how to get the coordinates of the corners of the bounding box. If I use:

box = mesh.bounding_box_oriented.primitive.extents

I get the half-lengths of each side of the bounding box, but if I use these to plot the 8 corners they form a box the same size and shape as the bounding box, but seemingly randomly oriented in space. How can I correctly get the coordinates of the corners so I can construct my meshgrid within the bounding box? I see that in bounds.py there is a function corners that seems to do what I want, but I don’t know where to get the bounds argument from.

Thank you for your time, Joel

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mikedhcommented, May 12, 2017

Hey, I think you may want to use mesh.bounding_box which is the axis aligned bounding box rather than mesh.bounding_box_oriented which is the oriented bounding box. Although in order to get the 8 corners of the OBB you could do: trimesh.bounds.corners(m.bounding_box_oriented.bounds)

The mesh.bounds property is computed and always axis- aligned, where the .primitive.extents is pre-transform (by .primitive.transform)

One thing you might consider, is that the oriented bounding box you’re using will probably have a lot less volume. You could generate the grid (axis aligned) the size of the OBB extents, and then transform the grid of query points using the OBB’s transform.

Some ipython noodling:


In [14]: trimesh.util.attach_to_log()

In [15]: m.bounding_box_oriented.primitive.transform
Out[15]:
TrackedArray([[   0.75983,   -0.49294,    0.42387,  831.14091],
       [   0.61234,    0.76166,   -0.21193,  437.48365],
       [  -0.21838,    0.42058,    0.88058,  636.10072],
       [   0.     ,    0.     ,    0.     ,    1.     ]])

In [16]: m.bounding_box.primitive.transform
Out[16]:
TrackedArray([[   1.     ,    0.     ,    0.     ,  831.14091],
       [   0.     ,    1.     ,    0.     ,  437.48365],
       [   0.     ,    0.     ,    1.     ,  636.10072],
       [   0.     ,    0.     ,    0.     ,    1.     ]])

In [17]: trimesh.bounds.corners?
Signature: trimesh.bounds.corners(bounds)
Docstring:
Given a pair of axis aligned bounds, return all
8 corners of the bounding box.

Parameters
----------
bounds: (2,3) or (2,2) float, axis aligned bounds

Returns
----------
corners: (8,3) float, corner vertices of the cube
File:      x:\trimesh\trimesh\bounds.py
Type:      function

In [18]: trimesh.bounds.corners(m.bounding_box.bounds)
[2017-05-12 18:21:23] DEBUG   (primitives.py:329) Creating mesh for box Primitive
[2017-05-12 18:21:23] DEBUG   (base.py:1212) Mesh transformed by matrix, normals restored
to cache
[2017-05-12 18:21:23] DEBUG   (util.py:686) triangles was not in cache, executed in 0.025009
[2017-05-12 18:21:23] DEBUG   (util.py:686) bounds was not in cache, executed in 0.025009
Out[18]:
array([[ 830.14391,  436.48424,  635.10141],
       [ 832.13792,  436.48424,  635.10141],
       [ 832.13792,  438.48306,  635.10141],
       [ 830.14391,  438.48306,  635.10141],
       [ 830.14391,  436.48424,  637.10002],
       [ 832.13792,  436.48424,  637.10002],
       [ 832.13792,  438.48306,  637.10002],
       [ 830.14391,  438.48306,  637.10002]])
0reactions
Emnaa12commented, Dec 3, 2021

m.bounding_box_oriented.vertices works correctly, thank you !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Find the 4 Corners of a Bounding Box of a Rotated, Offsetted ...
How does one find the coordinates of the 4 corners of a bounding box of a square of width w and height h...
Read more >
How to get Corners of Bounding Box? - three.js forum
Basically, I am trying to achieve explode and implode effect where my four cubes reach four corners of the bounding box from an...
Read more >
How to calculate a bounding box for a rectangle rotated ...
After rotation about corner x0, y0 by angle Fi rectangle center has coordinates cx = x0 + w/2*Cos(Fi) - h/2*Sin(Fi) cy = y0...
Read more >
How to define coordinates of orientated BoundingBox for ...
And [ vx(k),vy(k)] are the coordinates of 4 corners of bounding box. But my problem is, for different images the order of coordinates...
Read more >
How to create box mesh base on bounding box - Questions
You can also go through vectors (points), which basically represents corners that you are looking for. 1 Like. nogalo November 4, 2021, 2 ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found