This would be an easy implementation of a direct geometric solution.
1) First you need the line in a parametric form by calculating L0 and u:
say L(t) = L0 + t*u, where t is any real scalar
u is the line direction vector given by (R-Q). So, u = (x2-x1, y2-y1, z2-z1)
and L0 is Q = (x1, y1, z1).
Thus any point on the line can be generate by using some real value of t. In particular, here, L(0) gives you point Q, and L(1) gives you point R.
2) Check if line is parallel to plane (either never intersecting or completely lying in plane) i.e. if the plane normal vector n and line vector are perpendicular
if dot(n, u) == 0, that is the case
If the line is on the plane, then check if point Q (or R) is on the plane i.e it satisfies:
dot(n, Q-P) = 0 %the line between any two points on the plane is perpendicular to the normal vector.
Otherwise, the line never intersects the plane.
3) If the line is not parallel, then it intersects the plane at one point, which can be solved for:
t_int = dot(n, P - Q) / dot (n, R - Q )
and the point is simply L(t) = L0 + t_int* u
Here's some sample code you can use to define a function:
n = [1, 1, 1];
P = [2, 3, 0];
Q = [2, .51, 1];
R = [4, 1, 1];
L0 = Q;
u = R- Q;
if dot( n, Q-P)==0
disp('Line lies in plane')
disp('Line never intersects plane')
t = dot(n, P - Q)/dot(n, u);
POI = L0 + t*u;
fprintf('Point of intersection is [%f %f %f]', POI(1), POI(2), POI(3) )