Finding intersection points of a polar coordinate line inside of a rectangle

735 Views Asked by At

I have a line on a tangent to a circle defined in polar coordinates. The tangent is contained inside of a rectangle and I would like to find the intersection points with that rectangle. The rectangle's top left corner is (0, 0) and it is of a known size say (w, h).

Diagram

I could do this if I knew tangent in cartesian coordinates but I am stuck due to the fact that I only know the polar coordinates for the circle and how to then find the tangent from those coordinates.

I'm also concerned about the case where $\theta = 0$ as the tangent would have an infinite gradient. Although in that case $x = \rho$ so I could avoid that problem.

I would appreciate any help.

1

There are 1 best solutions below

0
On

This is much easier to do in Cartesian coordinates rather than polar. You can always convert back to polar once you’ve find the intersections, if any.

An equation of the tangent line at $(x_0,y_0)$ to the circle of radius $\rho$ centered at the origin is $xx_0+yy_0=\rho^2$. Assuming that you’re working in a left-handed coordinate system ($y$ increasing downward), you have $(x_0,y_0)=(\rho\cos\theta,\rho\sin\theta)$. Plugging this into the above equation gives $$x\cos\theta+y\sin\theta = \rho$$ as the equation of the tangent line. It looks like the rectangle’s sides parallel the coordinate axes, so finding the intersections of this line with the rectangle is a matter of substituting into this equation, solving for the remaining variable and making some range checks. Of course, when $\cos\theta=0$ or $\sin\theta=0$, the line is horizontal or vertical, respectively, which you might have to handle as simple special cases.