Uniformly scaled a cuboid to fit inside another cuboid

181 Views Asked by At

Lets say I have a cuboid V with any dimension (width, height, depth) and I have another cuboid M again with any dimension (width, height, depth) None of the cuboid V or M rotate.

I have to scale down or up cuboid M to fit inside cuboid V

Right now I am finding the largest dimension of cuboid M and scaling it to fit the smallest dimension of cuboid V

VSize = [v.width, v.height, v.depth]; MSize = [m.width, m.height, m.depth];

largestMSize = Largest(MSize) smallestVSize = Smallest(VSize);

scaleRatio = smallestVSize/largestMSize

I think this will guarantee cuboid M will fit inside cuboid V - BUT this is too extreme

Do you know of a way to calculate the correct scale for cuboid M to fit inside cuboid V?

THANKS

1

There are 1 best solutions below

0
On

Basic approach. You have three dimensions, and $M$ fits inside $V$ if and only if each of $M$'s three dimensions fits within the corresponding dimension of $V$. That is, $M$'s width fits in $V$'s width, $M$'s length fits in $V$'s length, and $M$'s depth fits in $V$'s depth.

How much do you have to scale $M$'s width to get it to fit? What about its length? Depth? Now, if they all have to fit, which of the three scaling factors should you use?