# Calculating edge coordinates of arrowhead. (pretty basic trigonometry)

What would be the most efficient (or right..) way to determine edge coordinates of both sides of arrowhead? Picture is worth a thousand words so I'll explain this with one. I know coordinates A and B, and will need coordinates C and D. Side of an arrowhead (S) is 10px and angle a is 0.5 rad.

I have done this with some (very basic) trigonometric functions and with a lot of if-else-statements. I know this can be done more wisely, but my knowledge ends after calculating angle of big arrow and subtracting 0.5 radians from that (that's obviously wrong since it doesn't change phase)

-
Have you considered making the head the origin and then performing simple coordinate geometry? –  picakhu Sep 27 '11 at 21:27
Or make $AB$ horizontal, with $A$ the origin, compute the coordinates and then rotate them back to the original position. Note that no angles need to be found for this rotation: just send $e_1$ to $AB$ and $e_2$ to $AB^\perp$. –  lhf Sep 27 '11 at 21:39
I think @pic has the right idea. Alternatively, you could repharse the same problem as vector addition. Namely, have A to B be a vector, and create a vector each for the left and right edges of the arrow head. Given b, the angle of the body of the arrow from horizontal, the right would be <Scos(b+pi+a) , Ssin(b+pi+a)> and the left <Scos(b+pi-a) , Ssin(b+pi-a)>. C, then is V_AB + V_left and D is V_AB + V_right. –  Drew Christianson Sep 27 '11 at 21:47

So, to derive the coordinates of C and D, first let A be the origin. For points $A = (a_1 , a_2) , B = (b_1 , b_2)$, B' is then $(b_1 - a_1 , b_2 - a_2)$ Then, define $$V_{B'}=<b_1 - a_1 , b_2 - a_2>$$. Then the magnitude of the vector is $\sqrt{(b_1 - a_1)^2 + (b_2 - a_2)^2} = M$. $\angle V_{B'}$ (the angle from the horizontal of the body of the arrow) is $arccos(\frac{b_1 - a_1}{M}) = b$ where arccos is the inverse cosine function (NOTE: this assumes the arrow is pointing up and to the left or right). This follows from the definition of a vector given M and b: $$<M cos(b) , M sin(b)>$$
We use that definition, along with S and b for formulate vectors $V_{left}$ & $V_{right}$ for the arrowheads: $$V_{right} = <S *cos(b + \pi - a) , S * sin(b + \pi - a)>$$ $$V_{left}=<S *cos(b+\pi+a),S*sin(b+\pi+a)>$$ Then, Point C $=V_{B} +V_{left}$ and Point D $=V_B + V_{right}$.