How to draw arrowheads? I am trying draw an arrow from $\begin{bmatrix}x_1\\y_1\end{bmatrix}$ to $\begin{bmatrix}x_2\\y_2\end{bmatrix}$. Here is my work.
If I draw an arrow rotating, then I can draw arrow pointing at any direction. Here is the Java code (full code). This section runs in infinite loop.
    x1 = 200; y1=200;
    x2 = 200+150*cos(angle); y2 = 200-150*sin(angle);
    a=20;
    phi = (float)Math.atan2(y2-y1, x2-x1);

    line(x1, y1, x2, y2);
    triangle(x2, y2,
            x2+a*(float)Math.cos(phi+2.88f),    // 165 deg = 2.88
            y2+a*(float)Math.sin(phi+2.88f),
            x2+a*(float)Math.cos(phi+3.4f),     // 195 deg = 3.4
            y2+a*(float)Math.sin(phi+3.4f)
            );

    angle+=.01;

But when I run this code, I get the arrow head is flipped for left half quadrants like this. Please help me figure out where I am wrong. Why does the arrow head flip for left half quadrant, i.e. when $x2<x1$?

Most likely your atan2() function isn't returning what you expect in that region. You may need to add $\pi$ to the result for those values (i.e., when $x_2<x_1$) to get the branch of $\tan^{-1}$ that you desire.
