Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- def remove_colinear( xy, threshold ):
- """
- This isn't a great algorithm but does a pretty good
- first-pass kind of job
- Computes the area of triangle for 3 points. If area is too big then
- we keep the middle point, otherwise we move onto the next one.
- """
- retval = [xy[0]] # always keep the 1st point
- for ii in xrange( 2, len(xy) ): # Polygon must have 3 points!
- x0 = retval[-1][0] # The last saved point
- y0 = retval[-1][1]
- x2 = xy[ii][0] # The current end-point
- y2 = xy[ii][1]
- x1 = xy[ii-1][0] # The middle point
- y1 = xy[ii-1][1]
- area = np.abs(0.5*((x1-x0)*(y2-y0)-(x2-x0)*(y1-y0)))
- if area > threshold:
- # If area is too big, then keep last point
- retval.append( xy[ii-1] )
- return retval
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement