Intersecciones de línea

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

preguntado el 09 de marzo de 12 a las 14:03

I would post it in the Math section or maybe Physics. -

This cannot always be done. If the lines are actually parallel, no extension will make them intersect. -

2 Respuestas

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.

respondido 09 mar '12, 14:03

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

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.

contestado el 23 de mayo de 17 a las 12:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.