java - Intercept between rectangle and line drawn from center point -


consider following diagram enter image description here

given center point of rectangle , origin, , coordinates b, how find @ point line ab intersects rectangle? thanks.

intersection coordinates relative center (a point):

dx = b.x - a.x dy = b.y - a.y if width * abs(dy) < height * abs(dx)    x = sign(dx) * width / 2    y = dy * x / dx else    y = sign(dy) * height / 2    x = dx * y / dy 

Comments

Popular posts from this blog

string - Using python and postgres, variables within execute function? -

python - Getting ESC characters and non-printables from UDP socket / buffer -