I am working on a MFC application that allows the user to draw some lines to construct a diagram that I will then analyze. I need to be able to place an arrowhead on the end of a line once the ser selects the end of the line by lifting the mouse button as he/she drags the line around the Cview screen.

I am having trouble developing an algorithm using LineTo and MoveTo functions to draw the arrowhead based on the location of the end point of the line. I need the arrowhead to be the same size for all lines. The trouble I am having is due to the fact that the line may be drawn at any angle ( 0 degrees - 360 degrees ).

Does anyone have some code or ideas on how to do this? Is there a way to do it with a bitmap if LineTo and MoveTo do not suffice?

consider a 45 degree angle

45:

assume line from (0,0) to (100,100)

theta = atan2(100-0,100-0) //0.7854 radians or 45 degrees

we now get a point on the line that is arrowsize pixels from the end.

// assume arrowsize is 10

x3 = 0 + (cos(theta) * arrowsize) // 0.7071 * arrowsize +0 is 7

y4 = 0 + (sin(theta) * arrowsize) // 0.7071 * arrowsize +0 is 7

by pythagorus (7^2 + 7^2) = arrowsize^2,

solving, we get arrowsize of 10. so we'd find the arrow center at 7,7, and it would have a lenght of 10.