# How to squash a rectangular prism without changing volume and expand the width and length by the same amount?

Ok so this is more of a math question than a unity question but here we go. My problem is I want to squash a rectangular prism (technically represented by a Vector3) without changing its volume. Shrink the height and expand the length and width to keep the volume the same, AND grow the length and width by an equal amount (if width goes up 0.5, length must go up 0.5) .

Additionally I say its a rectangular prism and not a cube because it will not have equal sides to begin with. Were it only that simple! I may be attempting to squash a rectangular prism with dimensions starting at width 2 height 6 and length 4 (with a volume of 48) and then attempting to squash that height to 5 and expand the width and length by X where (2 + X) · (4 + X) · 5 still equals 48.

I have been scouring the internet for a solution but so far I haven’t found anything that isn’t “You can find the volume by multiplying the height width and length!” Thank you internet, but that is not what I asked. “You can find the height with the volume width and length!” still not what I asked. Etc…

It is possible that I was not at all good at math in school, it is possible that its late and/or very early, it is possible I have been at this problem for four hours, it is even conceivable that all three are true so at this point I don’t know if I can’t find an answer to this problem online because it is remarkably simple, because it is impossible, because no one has asked it before, or I didn’t use the right keywords.

Any help solving this and/or explaining why it cant’t be solved would be greatly appreciated.

/*
Let’s say your rectangular prism starts off with L, W, H,
and you want to sqaush it to some new height h,
and calculate the new length and width l and w.
L and W change by the same amount, and the volume is unchanged.

``````so you want to find d, the delta in L and W:

setup:
1. l                            = L + d
2. w                            = W + d
3. lwh                          = LWH

solving:
4. (L + d) * (W + d) * h        = LWH
5. LW + Ld + Wd + dd            = LWH/h
6. dd + d(L + W) +  LW          = LWH/h
7. dd + d(L + W) + (LW - LWH/h) = 0
8. dd + d(L + W) + LW(1 - H/h)  = 0

which is a quadratic equation where
A = 1
B = L + W
C = L * W * (1 - H/h)

Using the standard quadratic equation will give you 0, 1, or 2 real solutions.
If you get 2 solutions, just pick one.
*/
``````

demo in WebGL here.