Jump to content

  • Log In with Google      Sign In   
  • Create Account


drawing an arrow in opengl


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 v71   Banned   -  Reputation: 100

Like
Likes
Like

Posted 12 October 2001 - 09:47 PM

Ok, i have two points in space, i get the vector direction (l,m,n) i want to draw a little arrow , but i don''t want to rotate a orthogonal vector using a quaternion , i would like to simply draw an arrow in 3d given two points, i have tried a lot of geometric formulas, axis of a segment and so on , but it didn''t come as i want , anyone knows / has code to do it ? thanks in advance

Sponsor:

#2 Jesper T   Members   -  Reputation: 322

Like
Likes
Like

Posted 13 October 2001 - 10:47 PM

Say: A = [x1, y1, z1] (start)
and B = [x2, y2, z2] (end)
and C = [x3, y3, z3] (arrow tip at one side)
and D = [x4, y4, z4] (tip at the other side)

if((z1-z2) != 0)
{
first we make a normal vector:
x3 = 1
y3 = 1
z3 = (-(x1-x2)-(y1-y2))/(z1-z2)

adjusting the distance from the arrow axsis to one fourth of the arrows lenght:
adj = sqrt((x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2)) / (4 * sqrt((x3^2)+(y3^2)+(z3^2)));
x3 *= adj
y3 *= adj
z3 *= adj

setting the other side:
x4 = -x3
y4 = -y3
z4 = -z3

gettin the point:
x3 = x1 + (3/4)*(x1-x2) + x3
y3 = y1 + (3/4)*(y1-y2) + y3
z3 = z1 + (3/4)*(z1-z2) + z3

x4 = x1 + (3/4)*(x1-x2) + x4
y4 = y1 + (3/4)*(y1-y2) + y4
z4 = z1 + (3/4)*(z1-z2) + z4
}

OK, I didnt doublecheck this, but the clue is the "first we make a normal vector:" -section, the rest is fairly straight out. Oh and if you use float or double values, they rarely become zero, but if (z1-z2) should happen to be zero, then find the normal setting z3 = 1, y3 = 1, and x3 = (-(y1-y2)-(z1-z2))/(x1-x2), that should work work aswell, and if (x1-x2) also is zero, just base it on y the same way.
Well, as I said, I didnt double check this, but I know it works, there might be simpler ways also, be sure to tell me if I made some stupid mistakes hehe




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS