2
$\begingroup$

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

$\tan^{-1}\left( \frac{m_1 - m_2}{1 + m_1m_2}\right )$ where $m_1 \gt m_2$

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

$\tan^{-1}\left(\frac{1.05555556+0.368567038}{1 + (1.05555556)(-0.368567038)}\right) = 1.16553753\space \text{radians} \approx 66^o$

This is correct if the line with slope $-0.3$ is moving down to the right while the line with slope $1$ is moving up to the right however the direction of the $-0.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
    +1 It is nice to see somebody give some thought to the problem before posting.2011-02-12

1 Answers 1

1

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.

  • 0
    Haven't come across it yet but I will surely make a note of it. Thanks for all the help guys I've been rattling my brain for days trying to figure this out.2011-02-12