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$?
phi
when you haveangle
on hand ? $\endgroup$ – Yves Daoust Dec 9 '16 at 14:33angle
in place ofphi
works as intended. But this is a test code. I was rotating the line to see if the arrow works in all direction. But in the original project, the arrow is to be drawn from point A to point B. $\endgroup$ – sigsegv Dec 9 '16 at 14:50