0

Im writing an application that will calculate the focal length of a camera based on the lines that can be seen in the photograph. For instance, if you take a picture of a room, the ceiling line can be one straight line (horizontal), the floor can be another straight line (horizontal) and the wall can be the third straight line (vertical). The aim of my application is for the user to select these straight lines one at a time, and once 3 lines are selected, the lines will need to be intersected to form a "triangle".

My problem is that because the lines selected don't necessarily intersect, how do I extend a line until it intersects with another line? In my application I have the start and end positions of all 3 user selected lines (Vector2's). But how do I extend each line until it intersect with the other 2 lines?

If anyone needs an image to clarify what I mean, send me a reply and Ill upload one to Flickr

genpfault
  • 51,148
  • 11
  • 85
  • 139
heyred
  • 2,031
  • 8
  • 44
  • 89

2 Answers2

0

Say each line is represented by two vector2's: v1 and v2, all the points in that given line will be given by the equation: p(x) = v1 + x(v2-v1). Each line will have its equation in this form. For each pair of lines, you will have to find the value of x that gives you the same p(x) for both equations; p(x) will be the point of intersection of those two lines.

Eduardo
  • 8,362
  • 6
  • 38
  • 72
  • If there is no value of x that gives you the same p(x), then you will be in the case Don mentions (parallel lines). – Eduardo Mar 09 '12 at 14:48
0

Sounds like you need to do 3 things.

  1. Extend the lines to the end of the picture (in your code, not visible to the user).

  2. Calculate line intersection. See this answer: detecting line intersection

  3. on the user's end, extend the lines until the intersection point if there is one on the picture.

Community
  • 1
  • 1
smcg
  • 3,195
  • 2
  • 30
  • 40