# Uniformly scaled a cuboid to fit inside another cuboid

Hello,
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)

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 = calculateLargestSize(MSize)
smallestVSize = calculateSmallestSize(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?
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
assuming you are not allowed to rotate V or M, and that M must maintain its aspect ratio
scale by smallest(v.width/m.width,v.height/m.height,v.depth/m.depth)
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
This would work if M is bigger than V (ratio < 1)

How about if M is smaller than V? (ratio > 1)

How about if M is smaller than V AND one side of M is smaller than V but the other side of M is bigger than V?

What do we do?

THANKS!
0
Commented:
if M is smaller than V? (ratio > 1), then scaleRatio will be >1

If M is smaller than V AND one side of M is smaller than V but the other side of M is bigger than V, then ScaleRatio will be <1 to ensure that the other side of M fits
0
Author Commented:
Thanks!
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.