java - Test if point is within line range on 2D space -


this question bit hard formulate i'll start showing image:

enter image description here

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:

enter image description here

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:

enter image description here

the dot product can shown be:

enter image description here

thus if θ > 90 dot(a, b) < 0, , vice versa. problem:

enter image description here

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

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -