Skip to content

Commit

Permalink
add a test to validate if a set of points is collinear
Browse files Browse the repository at this point in the history
  • Loading branch information
alessiofumagalli committed Jan 27, 2017
1 parent 03e6933 commit 316484b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,3 +519,26 @@ def compute_tangent(pts):
return tangent / np.linalg.norm(tangent)

#------------------------------------------------------------------------------#

def is_collinear(pts):
""" Check if the points lie on a line.
Parameters:
pts (np.ndarray, 3xn): the points.
Returns:
check, bool, if the points lie on a line or not.
"""

assert pts.shape[1] > 1
if pts.shape[1] == 2: return True

pt0 = pts[:,0]
pt1 = pts[:,1]

coll = np.array( [ np.linalg.norm( np.cross( p - pt0, pt1 - pt0 ) ) \
for p in pts[:,1:-1].T ] )
return np.allclose(coll, np.zeros(coll.size))

#------------------------------------------------------------------------------#

0 comments on commit 316484b

Please sign in to comment.