How do I convert a node's bounding box to a different coordinate system?

Nodes in SceneKit have a bounding box that is made up of two points: one with the smallest of all coordinates of the node and the other with the largest of all coordinates of the node. These coordinates are in the node's own coordinate system and I can't see how to find the bounding box in a different coordinate system.

For example, let's say that we have a node with this unit block geometry, with axes marked with .

or :

:

       :
  A---------+
  |    :    |
..|....:....|...
  |    :    |
  +---------B
       :

      

In its own coordinate system, node A is (-0.5, -0.5, -0.5) and B is (0.5, 0.5, 0.5). If the field is at point (45, 0, 0) in the world coordinate system, A will be (44.5, -0.5, -0.5) and B will be (45.5, 0.5, 0.5 ). We can get these values ​​by calling -[SCNNode getBoundingBoxMin:max:]

and then calling -[SCNNode convertPosition:toNode:]

.

But what if the node is rotated 45 ° around the Z-axis so that in the world coordinate system it looks like this?

        A
      /   \
    /       \
...+.........+...
    \       /
      \   /
        B

      

If you call -[SCNNode convertPosition:toNode:]

in this situation, you end up with a messed up bounding rectangle that has no width!

Is there a way to fix this?

+3


source to share


1 answer


to convert the bounding box (axially aligned) from one node to another, you need to convert 8 bbox vertices (not just min and max):

(min.x, min.y, min.z) (max.x, min.y, min.z) (min.x, max.y, min.z) (max.x, max.y, min. z) (min.x, min.y, max.z) (max.x, min.y, max.z) (min.x, max.y, max.z) (max.x, max.y, max.z)



then we analyze these 8 transformed vertices and find the new transformed min and max.

0


source







All Articles