# find point on edge of rect between two points

If I have a rectangle { x = 25, y = 135, width = 30, height = 15 }, and a random point { x = 235, y = 320 }, how can I find the point along the edge of the rectangle that is between the center of the rectangle, and the random point?

For example if I had the rectangle { x = 5, y = 30, width = 10, height = 20 } and I had the random point { x = 10, y = 55 }, the point I would be looking for is { 10, 30 }. How can I figure this out mathematically however?

-
Where is the rectangle located in the plane? Is the bottom left corner at $(0,0)$, for example? – Tara B Mar 3 '13 at 0:32

All you have to do is get the equations for the sides of the rectangle and the equation of the line though the center of the rectangle and the random point. Then find where this line intersects the line for the sides of the rectangle by equating the equations. Then eliminate the intersection points which are actually outside the rectangle but on the line if you extend the sides. Checking the solutions part is easier if you write the equations of the lines using vectors/parametric equation and normalize the parameter $t$ so that the intersection must be in $t \in [0, 1]$.