[SOLVED] Calculate the size of a plane

I’m slightly lost on how I would go about calculating the dimensions of a plane (or quad) based on the distance from the camera.

The image above shows a crude 2D view-point of a camera view in JME.

Given that “a” is the near plane with a value of 1.0 and “c” is the far plane, with a value of 1000.0 how would I calculate the angle of the leftmost point (the view-angle) so I can calculate the length of “b”?

What I am trying to do is calculate the size of a quad in respect to its distance away from the camera so that it fills the entire field of view. For example, if a (centered) quad was 160.0 wu’s away from the camera, what are the dimensions required to “fill the screen” with the quad from that distance.

Seems like a similar problem to what I faced when trying to move the camera to generate the tree atlases in SimArboreal. There is a magic projection matrix value that might be useful to you:

It’s kind of doing the reverse of what you want to do but the issue is the same.

2 Likes
// warning: untested code
assert !camera.isParallelProjection();
float near = camera.getFrustumNear();

float left = camera.getFrustumLeft();
float right = camera.getFrustumRight();
float width = right - left;
float xRatio = width / near;

float bottom = camera.getFrustumBottom();
float top = camera.getFrustumTop();
float height = top - bottom;
float yRatio = height / near;

float distance = 160f;
float quadWidth = xRatio * distance; // width needed
float quadHeight = yRatio * distance; // height needed

float xRadians = 2f * FastMath.atan(xRatio/2f); // the horizontal view angle
float yRadians = 2f * FastMath.atan(yRatio/2f); // the vertical view angle
2 Likes

Thanks to you both, they both work - and thank you for the math lesson @sgold .

1 Like