# Determine theta/radius line parameters from line segment endpoints

I've been working on this for the past few hours and am quite stuck!

As part of a computer vision exercise I've build a Hough transform that maps between the (x,y) space of an image, and a parameter space (theta,radius). Each point in this (theta,radius) space maps to a single line in (x,y) according to the formula:

$$r = x \sin{\theta} + y\cos\theta$$

Geometrically, this is explained in this image where the line segment is in red.

The transform is working correctly in one directly. However I'm now looking at a type of probabilistic Hough transform in which I select two candidate points from the x/y space, draw a line through them and and determine the coordinate in (theta,radius) space that corresponds to this line.

Essentially this is solving the two equations with two unknowns (theta,radius):

$$r = x_1 \sin{\theta} + y_1 \cos\theta$$ $$r = x_2 \sin{\theta} + y_2 \cos\theta$$

I've been trying, unsuccessfully, to solve this geometrically, but I think an equation should be easier to reason about. However my mathematical ability isn't up to the task of solving these equations. I set them equal to each other, leaving one unknown (theta) but wasn't able to get the two instances out to one side of the equation.

The goal is to process video on a robot with limited computing resource, so efficiency is also important.

Can anyone please point me in the right direction?

$$x_1 \sin\theta + y_1 \cos\theta = x_2 \sin\theta + y_2 \cos\theta$$

$$(x_1 - x_2) \sin \theta = (y_2-y_1) \cos \theta$$

Divide over $$(x_1 - x_2)\cos \theta$$

You'll get

$$\tan \theta = (y_2 - y_1)/(x_1 - x_2)$$

Get the tan inverse to know $\theta$, then given $\theta$ solve for the following equation to know $r$ $$r = x_1 \sin \theta + y_1 \cos \theta$$

Abbreviations Explained:

1. Line is constructed through segment AB, given by coordinates A=[x1,y1] and B=[x2,y2]
2. Perpendicular to the line is constructed from the origin [x3,y3] = [0,0]
3. Point of contact [x4,y4] between the line and its perpendicular (source: https://www.cyberforum.ru/cpp-beginners/thread125838.html#post707538 )

x4=((x2-x1)(y2-y1)(y3-y1)+x1*(y2-y1)^2+x3*(x2-x1)^2)/((y2-y1)^2+(x2-x1)^2)

y4=(y2-y1)*(x4-x1)/(x2-x1)+y1;

theta = atan2(y4,x4);

rho = x1*cos(theta)+y1*sin(theta) = x2*cos(theta)+y2*sin(theta);

• Value of theta here is quadrant-specific thanks to ATAN2, no quadrant corrections are required. Mar 17 '20 at 3:26