views:

363

answers:

2

1) I know the start point of the arrow and I know the endpoint.

I have no idea how to draw the head of the arrow.. I'm assuming that the other two points of the head are 45 degree angles away from the end point...

Anyone know of the formulas needed to do this?

+1  A: 

Why would this not work?

1) Draw a triangle for the head (meaning draw with GL_TRIANGLES, not draw 3 line segments that form a triangle)

2) Draw a line segment extending from the midpoint of the base of the triangle.

Wade Williams
+2  A: 

Wade gives a good answer for the OpenGL portion of this question; I'll try to answer the vector math portion. Here's some pseudocode off the top of my head:

Triangle GenerateArrowHead(vec2 p1, vec2 p2)
{
    // Compute the vector along the arrow direction
    vec2 v = Normalize(p2 - p1)

    // Compute two perpendicular vectors to v
    vec2 vPerp1 = vec2(-v.y, v.x)
    vec2 vPerp2 = vec2(v.y, -v.x)

    // Compute two half-way vectors
    vec2 v1 = Normalize(v + vPerp1)
    vec2 v2 = Normalize(v + vPerp2)

    Triangle tri;
    tri.a = p2;
    tri.b = p2 + ArrowHeadSize * v1;
    tri.c = p2 + ArrowHeadSize * v2;
    return tri;
}
prideout
You can change the angle of the head by multiplying vperp1 and vperp2 by some constant: use values < 1 to get less than 45 degrees, values > 1 to get greater than 45 degrees.
Ian Terrell