Skip to content

几何

三点共线

乘法代替除法可以避免判断分母为零。

// this is wrong
(a[0] - b[0]) / (a[1] - b[1]) != (a[0] - c[0]) / (a[1] - c[1]);
// this is also wrong.
(a[0] - b[0]) / (a[1] - b[1] + eps) != (a[0] - c[0]) / (a[1] - c[1] + eps);

// but this is OK
(a[0] - b[0]) * (a[1] - c[1]) != (a[0] - c[0]) * (a[1] - b[1]);