2
votes

Question:

I need to calculate intersection shape (purple) of plane defined by Ax + By + Cz + D = 0 and frustum defined by 4 rays emitting from corners of rectangle (red arrows). The result shoud be quadrilateral (4 points) and important requirement is that result shape must be in plane's local space. Plane is created with transformation matrix T (planes' normal is vec3(0, 0, 1) in T's space).

enter image description here

Explanation:

This is perspective form of my rectangle projection to another space (transformation / matrix / node). I am able to calculate intersection shape of any rectangle without perspective rays (all rays are parallel) by plane-line intersection algorithm (pseudocode):

Definitions:

// Plane defined by normal (A, B, C) and D
struct Plane { vec3 n; float d; };

// Line defined by 2 points
struct Line { vec3 a, b; };

Intersection:

vec3 PlaneLineIntersection(Plane plane, Line line) {
    vec3 ba = normalize(line.b, line.a);
    float dotA = dot(plane.n, l.a);
    float dotBA = dot(plane.n, ba);
    float t = (plane.d - dotA) / dotBA;
    return line.a + ba * t;
}

Perspective form comes with some problems, because some of rays could be parallel with plane (intersection point is in infinite) or final shape is self-intersecting. Its works in some cases, but it's not enough for arbitary transformation. How to get correct intersection part of plane wtih perspective?

Simply, I need to get visible part of arbitary plane by arbitary perspective "camera".

enter image description here

Thank you for suggestions.

2

2 Answers

0
votes

Intersection between a plane (one Ax+By+Cx+D equation) and a line (two planes equations) is a matter of solving the 3x3 matrix for x,y,z.

Doing all calculations on T-space (origin is at the top of the pyramid) is easier as some A,B,C are 0.

What I don't know if you are aware of is that perspective is a kind of projection that distorts the z ("depth", far from the origin). So if the plane that contains the rectangle is not perpendicular to the axis of the fustrum (z-axis) then it's not a rectangle when projected into the plane, but a trapezoid.

Anyhow, using the projection perspective matrix you can get projected coordinates for the four rectangle corners.

To tell if a point is in one side of a plane or in the other just put the point coordinates in the plane equation and get the sign, as shown here

0
votes

Your question seems inherently mathematic so excuse my mathematical solution on StackOverflow. If your four arrows emit from a single point and the formed side planes share a common angle, then you are looking for a solution to the frustum projection problem. Your requirements simplify the problem quite a bit because you define the plane with a normal, not two bounded vectors, thus if you agree to the definitions...

Description of the mathematical problem

then I can provide you with the mathematical solution here (Internet Explorer .mht file, possibly requiring modern Windows OS). If you are thinking about an actual implementation then I can only direct you to a very similar frustum projection implementation that I have implemented/uploaded here (Lua): https://github.com/quiret/mta_lua_3d_math

The roadmap for the implementation could be as follows: creation of condition container classes for all sub-problems (0 < k1*a1 + k2, etc) plus the and/or chains, writing algorithms for the comparisions across and-chains as well as normal-form creation, optimization of object construction/memory allocation. Since each check for frustum intersection requires just a fixed amount of algebraic objects you can implement an efficient cache.