Getting bounding box in custom axis
-
I need to find the bounding box max and min for a selection in a custom axis.
Is there a way to find the min and max vertices position from a custom axis such as for example the view direction?
Is there another better way? -
-
Thanks, but would it work for getting the bounds for the selection in the view direction? Something like this.
-
No.. sorry.. now (with your pic,) I see what you want.
If you could temporarily align the axis to the view, then the bounds would return what you want. BUT.. the API does not allow access to the Axis as a Ruby object.
-
It may be possible to temporarily transform the selection to align to the view, then change the camera to align to the axis, get your bounds, then reset the view, and undo the tranformation.
-
I'm thinking loud here:
Would it be possible to get the bounding box for the selection the ordinary way and then compare the min and max values of the bounding box in the Camera.xaxis and Camera.yaxis to see which is highest and lowest and use those values to generate a "view bounding box"? No idea how to do it though... -
@pixero said:
Thanks, but would it work for getting the bounds for the selection in the view direction? Something like this.
[attachment=0:7iscdulp]<!-- ia0 -->Viewbounds.jpg<!-- ia0 -->[/attachment:7iscdulp]Project the position of the vertices in the selection to the screen and use the projected points to create a new boundingbox?
-
I dreamt the solution last night and so far it's working. A few things to fix though.
What I'm doing is to get the bounding box of the selection the regular way.
Then make a copy of the boundingbox points in a array and rotate them around the center to match the camera rotation. Then test those rotated points in worldspace to see which are max and min for the different x, y, z axis and then use the corresponding bbox.corner index to create a new rotated bounding box.
Easy peasy.... perhaps not, but it seems to work.
By the way, any good example how to test the points to see which is max and min? -
In addition, the Ruby standard Array class has the Enumerable module mixed in, which gives all Arrays a max and min method.
In the Sketchup API, Point3d class is compatible with Array.
-
Thanks.
Advertisement