Notifications
Clear all

[Closed] Smallest volume box to fit a shape?

I have a question that may seem a bit odd, but bear with me for a moment.

As I understand it, Max automatically creates bounding boxes for objects based on… well I’m not sure exactly what it’s based on. Local coordinates? At any rate, the bounding box shape that is created is always a rectangular cuboid (in other words, all corners being right angles). What I would like to do is create a box that completely encloses whatever object, but has the smallest possible volume (in other words, with the 8 corners at whatever points they need to be regardless of position of angle for this to happen).

My most immediate concern is to try and get this working on a 2D basis. So, if I have a spline shape, it should create a surrounding quadrangle that does not intersect my shape, but is otherwise as small as possible. I really don’t know where to start though, so any advice is appreciated!

39 Replies

AFAIK the bounding box has “the smallest possible volume”. You can check the .max and .min property of an object to get the extremes of the bounding box.

I think what he is asking is, if you have a box and rotate it in subobject mode you could create a bounding box larger than the dimensions of the geometry inside. He wants a way to correct that, if I understand him correctly.

Okay… sometimes a rectangle (all right angles) is the smallest space you can fit something in, more often it’s some kind of irregular quadrangle (and with a triangle, I guess that 2 of the points would be right on top of each other).

Oh, I should also mention that I am looking specifically for convex quadrangles only.

This is not a trivial algorithm. Have you tried searching online? The maxScript part will be simple, but the underlying geometry won’t be easy.

I’m not sure there’s any way to do it but by trial and error. Think of an ellipse rotated at an arbitrary angle. The smallest area quadrangle is the rectangle with sides perpendicular to the ellipse’s axes, but how can you find them if you don’t know anything about the shape going in? You can pick an arbitrary tangent and adjust the other sides to see if they make the overall area go down, effectively “shrink wrapping” your quad around the shape, but I suspect that there are shapes that can “fool” this method by requiring that it expand some before it contracts to the optimal shape (which means you’d have to apply this shrinking algorithm from an arbitrary set of starting angles and compare the results and even then I’m not sure you’re guaranteed to find the best solution).

I’ll wrack my brain for a bit, but I’m very curious what you’d need this script for…

(and how accurate does it have to be?)

It’s a bit complicated. I’m doing a biomechanics related project to do with differences in spinal curvature. I’ve got a basic spine rig set up, and am using the quadrangles to represent each of the processes of the vertebrae. I’m using a skin wrap to attach the vertebrae to those quadrangles. So far I’ve been doing it by hand, but it’s been slow going. I need the quadrangles to each contain their “slice” as precisely as possible, so that when I make the changes to match the other sets, I know that they are lining up properly.

It sounds a little crazy, but it’s actually working pretty well shrugs

And, I don’t need a ridiculous level of accuracy.

3 Replies
(@denist)
Joined: 11 months ago

Posts: 0

Are your splines flat? If you need an optimal bbox in 2D space it’s easy. If all your splines are almost flat (or you can sacrifice one direction) the calculation is simple…

(@focomoso)
Joined: 11 months ago

Posts: 0

I don’t have max on this laptop to test, but I looked at your code and it looks as if you’re calculating the optimal rectangle whereas he needs the optimal irregular quadrangle (hence the added level of complexity).

Malkalypse: how complicated are the objects you need to bound? If there’s some limit to the concavity, that might help simplify things.

(@denist)
Joined: 11 months ago

Posts: 0

Originally the task was “Smallest volume box to fit a shape?” . Irregular quadrangle is not a box. There are some algorithms to create convex hull with any level of optimization… Does the optimal convex hall with 8 vertices work in this case?

Hi, sorry if I was not clear in my initial post. I DO want the optimal convex hull with 8 vertices. If you could point me in the direction of these algorithms, or even better a Maxscript implementation, I would be very grateful.

Regarding the question of the irregular quadrangles: in order to simplify matters, and because my solution up to this point has dealt with a group of various cross sections, I would be able to use a set of 2 dimensional shapes (the quadrangles) for my immediate needs.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

Do you need to get these Convex Hulls as meshes for any reason or do you want to use them as a subproduct for following calculations?

Do you want to use these “quadrangles” as (…?, bones?) for skin deformation? Why can you not use splines themselves? I’m still confused a bit. It seems like you are doing some overwork. Maybe I’m wrong…

I’m not sure convex hulls will work here as they assume an arbitrary number of vertexes. You could calculate the convex hull and then optimize it to 4 verts, but then you’re not guaranteed that the shape is entirely contained in the hull or that it is in fact the smallest area.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

the hull (thanks, focomoso) looks like a not right solution. It has to be anything simpler…

ok, Malkalypse, do we know anything about the orientation of the shapes going in? You say they are part of a vertebrae. Can we assume that the top and bottom sides of the quad are roughly perpendicular to the line running through the spine? If so, we could fake your algorithm.

Starting form the “top” of the shape – as defined by the position of the next vertebra – we find the line that passes through the two highest convex points. We do the same for the bottom, left and right. We’re not 100% guaranteed to have the smallest area, but we’ll have the smallest area that’s oriented roughly to shape of the spine. Imagine a rectangular bounding box oriented to follow the spine that’s squeezed in to conform to the shape. That wouldn’t be too hard to do.

Would that be good enough for your purposes?

Oh, and are the shapes guaranteed to be convex? And are they spline shapes or meshes? Some pictures might help.

Page 1 / 4