grains.geometry.is_collinear¶
-
grains.geometry.
is_collinear
(points, tol=None)[source]¶ Decides whether a set of points is collinear.
Works in any dimensions.
- Parameters
points (ndarray) – 2D numpy array with N columns, each row corresponding to a point, and the N columns giving the Cartesian coordinates of the point.
tol (float, optional) – Tolerance value passed to numpy’s matrix_rank function. This tolerance gives the threshold below which SVD values are considered zero.
- Returns
bool – True for collinear points.
See also
Notes
The algorithm for three points is from Tim Davis.
Examples
Two points are always collinear
>>> is_collinear(np.array([[1, 0], [1, 5]])) True
Three points in 3D which are supposed to be collinear (returns false due to numerical error)
>>> is_collinear(np.array([[0, 0, 0], [1, 1, 1], [5, 5, 5]]), tol=0) False
The previous example with looser tolerance
>>> is_collinear(np.array([[0, 0, 0], [1, 1, 1], [5, 5, 5]]), tol=1e-14) True