# Line intersection (normal form)

This topic is 3661 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all (it's been along time since I visited these shores), I'm currently working on a personal project where I need to detect rectangles in an image (computer vision). I have a fully working hough transform filter that returns a list of lines within an image. So with this list of lines I need to derive all the possible rectangles. Not a problem, the issue I have is finding the intersection point of 2 lines in normal form. Line equation (normal form). p = x cos(a) + y sin(a). I could convert the 2 lines into image space and do the standard intersection test. But this seems unnecessary. So I have 2 lines where I have values p & a, how can I determine the point(x,y) where the lines meet? Any help is much appreciated. Cheers Psy

Any takers?

##### Share on other sites
Intersection Algorithms
The LineToLineIntersection test takes in any two points on each line and returns the intersection of the lines.

##### Share on other sites
p1 = x cos(a1) + y sin(a1)
p2 = x cos(a2) + y sin(a2)
---------------------------------------------------------------------
sin(A - B) = sin(A) cos(B) - cos(A) sin(B)
---------------------------------------------------------------------
y = (p1 - x cos(a1)) / sin(a1)
y = (p2 - x cos(a2)) / sin(a2)

(p1 - x cos(a1)) / sin(a1) = (p2 - x cos(a2)) / sin(a2)

(p1 - x cos(a1)) * sin(a2) = (p2 - x cos(a2)) * sin(a1)

p1 sin(a2) - x cos(a1) sin(a2) = p2 sin(a1) - x cos(a2) sin(a1)

x cos(a2) sin(a1) - x cos(a1) sin(a2) = p2 sin(a1) - p1 sin(a2)

x (cos(a2) sin(a1) - cos(a1) sin(a2)) = p2 sin(a1) - p1 sin(a2)

x = (p2 sin(a1) - p1 sin(a2)) / (cos(a2) sin(a1) - cos(a1) sin(a2))

x = (p2 sin(a1) - p1 sin(a2)) / (sin(a1) cos(a2) - cos(a1) sin(a2))

x = (p2 sin(a1) - p1 sin(a2)) / sin(a1 - a2)
---------------------------------------------------------------------
x = (p1 - y sin(a1)) / cos(a1)
x = (p2 - y sin(a2)) / cos(a2)

(p1 - y sin(a1)) / cos(a1) = (p2 - y sin(a2)) / cos(a2)

(p1 - y sin(a1)) * cos(a2) = (p2 - y sin(a2)) * cos(a1)

p1 cos(a2) - y sin(a1) cos(a2) = p2 cos(a1) - y sin(a2) cos(a1)

y sin(a2) cos(a1) - y sin(a1) cos(a2) = p2 cos(a1) - p1 cos(a2)

y (sin(a2) cos(a1) - sin(a1) cos(a2)) = p2 cos(a1) - p1 cos(a2)

y = (p2 cos(a1) - p1 cos(a2)) / (sin(a2) cos(a1) - sin(a1) cos(a2))

y = (p2 cos(a1) - p1 cos(a2)) / (sin(a2) cos(a1) - cos(a2) sin(a1))

y = (p2 cos(a1) - p1 cos(a2)) / sin(a2 - a1)
---------------------------------------------------------------------

don't forget to check for parallel lines
as sin(angle) == 0 when angle == n PI with n integer

1. 1
2. 2
3. 3
Rutin
20
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633656
• Total Posts
3013186
×