3d line intersection on the same plane

I know the lines are on the same plane but they’re in 3d. So I know the way to test is to test if they collide in 2d, but how can I convert the points from 3d to 2d? I have the normal information of the plane and points, I just don’t understand how to convert the points from 3d to 2d, thanks.

Transform the lines to barycentric coordinates on the plane, then use the 2D test.

I e, if you have a plane normal, come up with two other vectors that are perpendicular to the normal, and to each other. These, together with the normal, make up a basis for the plane (i e, a rotation matrix that will put an object into the space of the plane).

Now, call these vectors “tangent” and “binormal”. For each input vertex “inv” for each line you want to test, execute:

outv.x = dot3( tangent, inv );
outv.y = dot3( binormal, inv );

This gives you 2D lines using the “outv” vertices. Test these lines using your existing 2D code.

Btw: this isn’t really advanced, and it’s not really OpenGL, either…

First normalize the normal vector.
Then compute the dot product of the normal with the Z-axis (0.0,0.0,1.0) … so actually the z component of the normalized normal … this will give you the cosine of the angle between the normal and the z-axis.
Next compute the vertex perpendicular to both the normal and the z-axis by computing the cross product of the normal and the z-axis ( this equation can also be simplified beacuse the Z-axis is defined as (0.0,0.0,1.0) ).
Use this vertex and angle ( don’t forget to take the arccosine and watch for radians/degrees conversions) in glRotatef(angle,vertex_x,vertex_y,vertex_z)
This will transform your points to lie in a plane parallel to the XY plane, so you can ignore the z-coordinates.

N.