0
$\begingroup$

I am programming an application that renders lines in 2d space. Each line has a direction, the direction = the angle between the 1st and last vertex on the line. I am attempting to determine the direction of 2 separate lines(each contain many 2d vertices) and re-orientate(reverse) them if they don't face the direction I require.

Criteria:

  • If those 2 lines both face towards the intersection point then I need to reverse one of them so they sit 'head-to-tail'.
  • If neither face the intersection point then I need to reverse one of them so they sit 'head-to-tail'.
  • If one faces the intersection point and the other does not then I do nothing, they already are 'head-to-tail'.

Do you know of a methodology(mathematical function, algorithm or other) that would allow me to determine whether 2 lines meet 'head-on', 'tail-on' or 'head-to-tail'?

I think it also becomes especially difficult when the 2 lines do not physically intersect. But in this case I still need to determine their directions and ensure that IF they did intersect, that it would be a 'head-to-tail' intersection.

  • 0
    How is the angle between two points defined? What does it mean for a line (segment?) to 'face' a certain way? What are heads/tails? What does it mean to 'reverse' a line (segment?)?2012-06-21
  • 0
    If the intersection point is in the interior of a line segment (rather than at an end) then part of the segment "faces the intersection point" and part does not2012-06-21

1 Answers 1