How to calculate the projection height values of a scene?

Hello! I want to code myself a little tool to calculate the height and width of a shape that is not in the 3d scene, but on my screen. Not sure how to achieve this or whether I can get the needed params out of the box:

Clarifications: in the image h2 should correspond to the visible 2D height from the left back corner to the right front corner.
w2 should be from right front edge to the right back edge
w1 from right to left front edges

In what space do you want to compute these values? Depending on whether the height values should be expressed e.g. as pixels or world units, the computation will look totally different.

Well, I technically don’t care about that as I only need proportions between all the values. I am probably searching for the most efficient path to do this. With a lot of trigonometry I think that it would be possible to calculate the needed distances in world coords, but ehh - looks very inefficient and ugly

In this case, you have to extract the corner points in local space from your geometry and then transform these points into world space. This can by copying a vertex into an instance of Vector3 and then multiplying the world matrix of the respective 3D object:

v1.applyMatrix4( object.matrixWorld );

When the vertex is in world space, you can use Vector3.project() to transform the vertex into the camera’s normalized device coordinate (NDC) space. It should then be possible to compute the mentioned proportions.

1 Like