algorithm - How to find out if a ray intersects a rectangle? -


we have ray starts @ point a(x, y) , goes on forever through given point b(x, y) != a. have rectangle defined points k,l,m,n each (x, y).

i wonder how detect if our ray intersects point of our rectangle (get bool, not precice coordinates)? algorithm calculating such value?

let me straight. have vector v headed off in direction (b_x - a_x, b_y - a_y) , starting @ (a_x, a_y).

consider vector w = (b_y - a_y, a_x - b_x). @ right angles first. (verify dot product.) therefore point (p_x, p_y) can tell side of vector on taking dot product of (p_x - a_x, p_y - a_y) w , looking @ sign.

so take dot product 4 corners of rectangle. if give 0 dot product, on vector, if signs change there intersection, if sign same there no intersection.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

asp.net mvc - Implementing normal user/pass, Twitter & Facebook auth -