drawing an arrow

Hi,

I have two points in 3d space:

point1 (x,y,z)
point2 (x,y,z)

I want to draw an arrow from point1, to point2. At point2, I’d like to draw a small pyramid head cap to indicate direction. I CANNOT find a formula for generating some based points for a head given the two end points of the arrow.

Does anyone have such a formula? I need something like:

headBasePt0 = (x,y,z); // point 3 in picture
headBasePt1 = (x,y,z); // point 4 in picture
headBasePt2 = (x,y,z); // point 5 in picture
headBasePt3 = (x,y,z); // point 6 in picture

Here’s a drawing of what I’m aiming for:
http://i87.photobucket.com/albums/k153/bnf_intro/arrow_example.jpg

Thanks

//1. create unit-length vector from point2 to point1
v1 = point1 - point2
v1 = normalize(v1)

//2. create two more unit-length vectors
v2 = cross(v1, (1, 0, 0))
if (length(v2) < 0.001)  //just in case
{
  v2 = cross(v1, (0, 1, 0))
}
v2 = normalize(v2)

v3 = cross(v1, v2)
v3 = normalize(v3)  //not really necessary

//3. v1,v2,v3 form a 3x3 matrix now - create arrow and transform by that matrix. Assume v1 is Z axis and v2 is X axis
//unrotated arrow points
p0 = vec3(-1, -1, 1)
p1 = vec3( 1, -1, 1)
p2 = vec3( 1,  1, 1)
p3 = vec3(-1,  1, 1)
//transform by 3x3 matrix
p0 = dot(p0, v2), dot(p0, v3), dot(p0, v1)) + point2
p1 = dot(p1, v2), dot(p1, v3), dot(p1, v1)) + point2
p2 = dot(p2, v2), dot(p2, v3), dot(p2, v1)) + point2
p3 = dot(p3, v2), dot(p3, v3), dot(p3, v1)) + point2

Ok, that can be more less called a code… Untested :wink:
I assume I don’t have to explain dot(), cross(), length() and normalize().
Happy easter!