algorithm - Tangents range for all pairs of points in a box -
suppose have box lot of points. need able calculate min , max angles lines go through possible pairs of points. can in o(n^2) times enumerating every point others. there faster algorithm?
taking idea of dual plane proposed evgeny kluev, , comment finding left-most intersection point, i'll try give equivalent direct solution without dual space.
the solution simple: sort points (x, y) lexicographically. draw line through each 2 adjacent points in sorted order. can proved minimal angle achieved 1 of these lines. in order maximal angle, need sort (x, -y) lexicographically, , check adjacent pairs of points.
let's prove idea min angle. consider 2 points a , b yield minimal possible angle. among such points can choose pair minimal difference of x coordinates.
suppose have same y. if there no other point between them, adjacent. if there points between them, @ least 1 of them adjacent a in our order, , of them yield same angle.
suppose there exists point p x-coordinate in between a , b, i.e. ax < px < bx. if p lies on ab, ap has same angle less difference of x coordinates, hence contradiction. when p not on ab, either ap or pb give less angle, gives contradiction.
now have points a , b lying on 2 adjacent vertical lines. there no other points between these lines. if a , b points on vertical lines, ab pair adjacent in sorted order , qed. if there many points on these lines, minimal angle achieved taking highest point on left vertical line (which must a) , lowest point on right vertical line (which must b). since sort points of equal x y, these 2 points adjacent.
Comments
Post a Comment