Are the two points meant as end points of a line segement, or just two points on a line, which has infinite length?
function R = isPointOnLine(P1, P2, Q, EndPoints)
P12 = P2 - P1;
L12 = sqrt(P12 * P12');
N = P12 / L12;
PQ = Q - P1;
Dist = abs(N(1) * PQ(2) - N(2) * PQ(1));
Limit = 10 * eps(max(abs(cat(1, P1(:), P2(:), Q(:)))));
R = (Dist < Limit);
if R && nargin == 4
L = PQ * N.';
R = (L > 0.0 && L < L12);
This considers line in all directions, rounding errors and if the 4th input is used, Q must be element of the line between P1 and P2.