Camera frustum intersection with plane

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By beegor

Hi,
What would be the fastest way to calculate polygon which is intersection of camera frustum and a plane?

Something like this:
enter image description here
Picture taken from similar StackOverflow question: geometry - How to calculate correct plane-frustum intersection? - Stack Overflow

Some things that might make things easier: camera is always facing that plane, and the plane is actually xz plane of world coordinate system.
I didn’t find any out of the box function for calculating this.
One idea I have is to take frustum lines and get line-plane intersection for each line, but Camera.get_frustum ( ) is not documented, it says only it returns Array, I can only guess that it is Array of vertices, but can’t be sure. And if it is vertices, in what order?
Thanks.
Igor

:bust_in_silhouette: Reply From: Wasiim

You can calculate it yourself, as follows

made a slight error in the image above, you should know
theta = fovy/2

where width/height is the width and height of your window

if you simply want the lengths of the rectangle cross section then

y_length = y_max * 2
x_length = x_max * 2

EDIT:
I realized you wanted to solve this for any arbitrary plane, this is how you would do that. There’s 2 images in that link btw.

capital C which is the camera position is not to be confused with lowercase c which is a component of the plane’s normal vector.

Also in the final equation for t, notice the bottom of the division it should be c * Znear and not just Znear. You’d also probably want to write that last equation in dot product form.

t = [(-N dot cameraPos) + D] / (N dot nearPlaneCorner[i])

Essentially, finding these 4 points of the trapezoid is a function of the plane equation, the camera position, the fov of the camera, the width and height of the window, and znear.

I solved the equation for only the top left point of the trapezoid. But you can generalize this to find all four, the only thing you’re changing is Dy and Dx. You must realize the cross section for these planes are going to yield trapezoids. The only situation in which we get a rectangle is when the normal of the plane is parallel to the vector (0, 0, 1), as illustrated in the example above.