Let's call a and b your rectangle sides, and (x0,y0) the coordinates of your rectangle center.
You have four regions to consider:
Region from to Where
====================================================================
1 -arctan(b/a) +arctan(b/a) Right green triangle
2 +arctan(b/a) π-arctan(b/a) Upper yellow triangle
3 π-arctan(b/a) π+arctan(b/a) Left green triangle
4 π+arctan(b/a) -arctan(b/a) Lower yellow triangle
With a little of trigonometry-fu, we can get the coordinates for your desired intersection in each region.
So Z0 is the expression for the intersection point for regions 1 and 3
And Z1 is the expression for the intersection point for regions 2 and 4
The desired lines pass from (X0,Y0) to Z0 or Z1 depending the region. So remembering that Tan(φ)=Sin(φ)/Cos(φ)
Lines in regions Start End
======================================================================
1 and 3 (X0,Y0) (X0 + a/2 , (a/2 * Tan(φ))+ Y0
2 and 4 (X0,Y0) (X0 + b/(2* Tan(φ)) , b/2 + Y0)
Just be aware of the signs of Tan(φ) in each quadrant, and that the angle is always measured from THE POSITIVE x axis ANTICLOCKWISE.
HTH!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…