Jump to content
  • Advertisement
Sign in to follow this  
Psyian

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.

If you intended to correct an error in the post then please contact us.

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

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!