# 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?
Asked:
###### Who is Participating?

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

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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

## Already a member? Login.

All Courses

From novice to tech pro — start learning today.