View Full Version : Finding Intersecting Line between Two Polygons

08-30-2010, 06:26 AM
Suppose, I have two polygons, one consisting of a number of triangles and another a number of quads. What is the easiest way to find the intersecting line between the polygons.

Any suggestion will be highly appreciated.

carsten neumann
08-30-2010, 08:09 AM
Since your polygons are flat, you can consider this as intersecting two planes, this will give you the infinite line that is common to both planes.
You can then test if there are points on the borders of the polygons that belong to that line and if so determine a line segment that is common to both polygons.

08-30-2010, 10:41 AM
carsten gave a good solution, assuming all your triangles and quads are really planar. (jenny_wui implied they are.)

Here's another approach. Which to use depends on whether you just want to draw the intersecting line or you want to use the equation of the line for some computation.

Draw your first polygon, but disable writing to the color buffer (in other words, just render to the depth buffer). Now draw your second polygon, but this time enable writing to the color buffer and set the depth test function to be GL_EQUAL with glDepthFunc() and disable writing to the depth buffer (but keep it enabled). This should just render the fragments that are common to both polygons. The line(s) might be drawn broken; if so, you might have to explicitly test the depth buffer in the fragment shader to allow a small fuzz factor for the "equality" test. Works even if your geometry isn't planar. Pretty easy!

08-31-2010, 02:46 AM
Thank you very much for your reply. I am not quite sure how the first method works when one quad intersects with a number of triangles. It would be very nice if any explanation is given.

I am pretty new in OpenGL. Many concepts of OpenGL are quite new to me. For second method can any example be given? With intersecting line, I also need to show both poygons.

Thanking you in advance.