# Finding the appropriate slope between two lines (slopes)

I am working on a texturing algorithm for 3d graphics and I am trying to rotate triangles that are attached at a point so that they are connected (share a single edge) I am using

$\arctan( \frac{m1 - m2}{1 + m1*m2} )$ where $m1 \gt m2$

This is working well in some test cases but not in all... I have two lines one with slope ~1 and ~-.3 which gets me

$\arctan(\frac{1.05555556+0.368567038}{1 + 1.05555556*-0.368567038)})$ = 1.16553753 radians = ~66 degrees

This is correct if the line with slope -.3 is moving down to the right while the line with slope 1 is moving up to the right however the direction of the -.3 slope is moving up and to the left. Is there a way to parameterize this function so that I can provide the direction the lines moving in? Thanks.

-
+1 It is nice to see somebody give some thought to the problem before posting. –  Ross Millikan Feb 12 '11 at 16:14

There are two angles to choose from. One will be 180 degrees minus the other. If you take a vector along each direction and take the dot product, it will be negative when you want the angle greater than 90. So in your example, if both lines are moving to the right $(1,1)\cdot(1,-0.3)=0.7\gt0$ so you want the 66 degree solution. In the second case $(1,1)\cdot(-1,0.3)=-0.7\lt0$ so you want the 180-66=114 degree solution.