intersection line of 3d polygons

I need to be able to find the intersection line between a 3d triangle and a 3d quad. they will both always be coplanar (their points, not to each other).

right now the only thing i can think of is to:

  1. get the planes of both polygons, then get the intersection line between them

  2. for each side of both polygons: get a plane perpendicular to the ploygon’s plane that lies along the side. clip the intersection line to each plane.

this seems rather inefficient to me, and i was wondering if anyone could suggest a better way.

Find a normal N to the quad (as robustly as possible!)

Pick a point P in the quad. In the interests of robustness, my intuition says that you want the corner nearest the centroid of the triangle.

For each vertex V_i of the triangle, compute d_i = (V_i - P) . N.

If all three vertices have the same sign dot product, there is no intersection. Otherwise they will split 1-2. [1] Wlog say that V_0 is positive and V_1 and V_2 are negative.

The intersection between the triangle and the plane of the quad runs from (d_0 V_1 - d_1 V_0) / (d_0 - d_1) to (d_0 V_2 + d_2 V_0) / (d_0 - d_2). Then clip that against the quad.

[1] Ignoring the special case where one of them is 0.