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.

-
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?)? – anon Jun 21 '12 at 6:09
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 not – Henry Jun 21 '12 at 6:48

I'm just getting started here so I can't comment only answer. Nevertheless the following pointers are more helpful commentary than answers.

You mean 'line segment' instead of 'line'. Lines have infinite extent, whereas line segments have finite extent, and rays have infinite extent but only in one direction from their origin.

If you want to think in terms of simplices in accordance with your invocation of vertices, you could call them edges / simplices/simplexes.

It's not clear what you mean by "angle between the first and last vertex on a line". Vertices are points; between two points there is no angle generated.

Maybe you have a simplex with multiple vertices, and you mean the angle between the first and last edge of the simplex, i.e. the angle between the line segment between 1st, 2nd vertex and the line segment between second-to-last and last vertex.

All of this is just speculation.
You have not formulated you problem well. Try to elaborate and be more precise.

-
I don't think an answer was possible. I don't know how much rep is needed to comment, but the 10 you get from my upvote will help. Good comments on an ill-posed problem. – Ross Millikan Sep 28 '12 at 3:32