java - Test if point is within line range on 2D space -
this question bit hard formulate i'll start showing image:
i want test if points (such p1 , p2 on image) within dotted lines perpendicular line @ limits. know coordinates of points test , line's limits.
so p1 false, , p2 true.
what computationaly efficient way calculate this?
i'm working floats in java.
this can efficiently done dot product:
this positive if a has component parallel b, , negative if anti-parallel.
therefore if have line segment defined points a , b, , test point p, need 2 dot product operations test:
dot(a - b, p - b) >= 0 && dot(b - a, p - a) >= 0
edit: graphical explanation:
the dot product can shown be:
thus if θ > 90 dot(a, b) < 0, , vice versa. problem:
in case 1, when dot(a - b, p - b) > 0 p on correct side of dotted line @ b, , vice versa in case 2. symmetry can same operation @ a, swapping a , b.





Comments
Post a Comment