I have a quad type which is defined as:
typedef struct __point {
float x;
float y;
} point_t;
typedef struct __quad {
point_t p1;
point_t p2;
point_t p3;
point_t p4;
} quad_t;
If I have two of those quads on the same plane, I would like to be able to work out the intersection points of those quads. For example, if we have quad A and quad B, if any of B's points fall outside of A, the algoritm should yield a quad with points as shown in the illustration below (A is in red, B is in purple):
Edit: Ordering of the points is not important because I will later use those points to construct a quad that is going to be drawn inside A.
If the only reason to do this is to draw the resulting polygon, why not use the GPU to do the work for you - you're using OpenGL after all. So instead of messing about working out how to construct the intersection, do the following:-
Set Z values of Polygon A and Polygon B to some constant
Set Z test to no testing (always write Z regardless)
Disable Z test
Enable Z writes
Disable colour writes
Render Polygon A
Set Z test to z equal
Enable Z test
Disable Z write
Enable colour write
Render Polygon B
Hey presto, the intersection polygon!
You could probably make this far more efficient if you restricted yourself to OpenGL 4 and used the various shaders that are available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With