Collinearity of 3 points

#include<bits/stdc++.h>
#define ll long long

// input: 3 points
// output: answer if 3 points are collinear (form a straight line)
template <typename T> collinear_3_points(T x1, T y1, T x2, T y2, T x3, T y3) { 

    T a = x1 * (y2 - y3) +  
          x2 * (y3 - y1) +  
          x3 * (y1 - y2); 
  
    if (a == 0) 
        return true;
    else
        return false;
} 

Leave a Reply