Calculate the distance between the line and the center of the circle:
P1 = [-2, -2];
P2 = [2, 2];
C = [0, 0];
R = 2;
P12 = P2 - P1;
N = P12 / norm(P12);
P1C = C - P1;
v = abs(N(1) * P1C(2) - N(2) * P1C(1));
doIntersect = (v <= R);
The geometrical explanation is easy: The cross-product replies the area of the parallelogram build by the normal of the line and the vector fro P1 to C. The area of this parallelogram is identical to the area of the rectangle build by the normal N and the vector orthogonal to N through C. The value of this area is the distance multiplied by 1 (the length of the N). Summary: The distance between the line and a point in 2D is the absolute value of the 3rd component of the cross-product between N and the vector from P1 (or P2) to C.
All you have to do is to compare, if this distance is smaller or equal to the radius.
In 3D the norm of the 3D cross-product is needed:
Best Answer