# What is the range of parameters rho and theta in normal equation of a straight line?

I'm implementing Hough Transform in MatLab to detect straight lines in an Image. It uses normal form of a straight line equation $$x\ cos(\theta) + y\ sin(\theta) = \rho$$

I'm interested in the lines which pass through the 1st quadrant only, that too in the rectangle with vertices $$(0,0), (M,0), (0,N), (M,N)$$ i.e. any line that doesn't pass through this rectangle, I'm not interested in finding the equation of that line. Orientation of the line can be anything. What is the range of values for the parameters $$\rho$$ and $$\theta$$?

If I assume $$\theta$$ varies from $$-90^\text{o}$$ to $$90^\text{o}$$, what is the range of values for $$\rho$$? Can $$\rho$$ be negative? As depicted in the graph we have better split for negative anf for positive values of $$\theta$$.
Thus we must have $$\left\{ {\matrix{ {\left\{ \matrix{ - \rho /\cos \theta \le M \hfill \cr - \rho /\sin \theta \le N \hfill \cr} \right.} \hfill & {\left| {\; - \pi /2 < \theta < 0} \right.} \hfill \cr {\left\{ \matrix{ \rho /\cos \theta - N\tan \theta \le M \hfill \cr 0 \le \rho \hfill \cr} \right.} \hfill & {\left| {\;0 < \theta < \pi /2} \right.} \hfill \cr } } \right.$$ that is $$\left\{ {\matrix{ { - M\cos \theta \le \rho \le - N\sin \theta } \hfill & {\left| {\; - \pi /2 < \theta < 0} \right.} \hfill \cr {0 \le \rho \le M\cos \theta + N\sin \theta } \hfill & {\left| {\;0 < \theta < \pi /2} \right.} \hfill \cr } } \right.$$