Given a square (described by x, y, width, height) and an angle (in radians) I need to calculate a vector that originates at the squares centre and terminates at the point th
Generalized to rectangles, if a = the angle of vector from the horizontal increasing counter cloclkwise, then the points coordinates can be calculated by the following:
let dx = distance from center horizontally, and
dy = distance form the center vertically, then
dx = if (tan(a) == 0, then width/2, else Min( height / (2 * tan(a)), width/2)
dy = if ABS(a) == Pi/2 then height/2 else Min( (width/2) * tan(a)), height/2)
Then coordinates of the point are:
px = (x+width/2) + dx for right quadrants (Pi/2 >= a >= - Pi/2);
= (x+width/2) - dx for left quadrants (Pi/2 <= a <= 3Pi/2)
py = (y+height/2) + dy for lower quadrants (Pi <= a <= 2Pi);
= (y+height/2) - dy for upper quadrants (0 <= a <= Pi);