Counting the number of intersection points when joining $n$ points to each other.

49 Views Asked by At

While solving another problem, I got the following problem;

On the $xy$-plane, there are $n$ known points $P_1(x_1,y_1),P_2(x_2,y_2),P_3(x_3,y_3),\dots,P_n(x_n,y_n)$.

Each point is connected to all $(n-1)$ points with straight lines.

Note: $P_1,P_2,P_3,\dots,P_n$ are intersection points.

Note: If more than two lines intersect at the same point, then this point must not be counted more than once.

Considering the region: $\{ x_\text{min} \le x \le x_\text{max},y_\text{min} \le y \le y_\text{max} \}$, how to count the number of the intersection points if we are given the coordinates of $P_1,P_2,P_3,\dots,P_n$?

I have no idea except listing the points of intersection after solving every possible combination of equations of two lines. This is painful!

Expecting an elegant way, may be determinants or otherwise.

Any help would be really appreciated. THANKS!