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

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -