It is true that as an object moves towards you (specifically with translateZ
), it appears larger (using scale
).
In the illustration provided, perspective
determines the viewer's position in relation to the container, while translateZ
indicates the subject's location relative to the container.
The conversion formula between scale and translateZ:
-OR-
While I won't dive into the mathematical proof, after verifying with the Pythagorean theorem, everything aligns correctly.
For instance:
Assume you are positioned 100px from the container:
#container { perspective: 100px; }
- If you use
translateZ(50px)
, the subject advances halfway towards you, resulting in a double appearance size, making it 2x.
- By implementing
translateZ(75px)
, the subject shifts further halfway closer, doubling again to make it 4x.
- Continuing this pattern, nearing
translateZ(100px)
will cause the subject to approach infinite largeness.
Feel free to experiment. Here is a JSFiddle for visual comparison of various scenarios.
Constraints:
This principle remains effective when the subject directly approaches you but loses effectiveness if you introduce actions like rotating the subject in 3D space. There are corresponding math formulas, but they can become intricate. Refer to Wikipedia's 3D Projection page for more information.