drawing an arrow

Started by
15 comments, last by Zakwayda 17 years ago
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); headBasePt1 = (x,y,z); headBasePt2 = (x,y,z); headBasePt3 = (x,y,z); I don't need any help with drawing it, just finding some points to use. Then I can connect the dots and have a nice wireframe arrow. Thanks
Advertisement
I think it is a matter of a)determining the direction the line will face in relation to point1, b)having a preexisting arrow head model, c)rotating that arrow head model to point the same direction as the line, d)translating the arrow head model to point2

I don't work with 3D drawing and I'm not sure exactly what API calls it would take to perform the above steps, though, sorry. Hope it helps.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

for an arrow from A -> B

get the vector pointing from B -> A
normalize it
scale it by the lenght of your arrow head

rotate it 30degrees (or whatever looks good) clockwise
add it to B's position (thats' one point) call it point C

rotate it 30degrees (or whatever looks good) counter-clockwise
add it to B's position (thats' the other point) call it point D

then you:
draw a line from A -> B
draw a line from B -> C
draw a line from B -> D

now you have an arrow that looks like this:
     C A -- > B     D

-me
Hi,

I made a drawing of what I mean:

http://i87.photobucket.com/albums/k153/bnf_intro/arrow_example.jpg

@Palidine:

Won't that draw an arrow only in 2D space?

Thanks
Also I have this snippet:

point0 can be any point not along the line through point1 and point2
perpendicular0 = (Point1-Point2) × (Point0-Point2)
perpendicular1 = perpendicular0*(radius of cone)/|perpendicular0|
perpendicular2 = perpendicular0 × (Point1-Point2) / |Point1-Point2|
pontx = point2+(point1-point2)*(length of cone)/|Point1-Point2| + sin(x)*perpendicular1+cos(x)*perpendicular2


but I'm not sure what to do what a component of perpendicular0 is zero - then I'll get a divide by zero.
Quote:Original post by markww
Also I have this snippet:

point0 can be any point not along the line through point1 and point2
perpendicular0 = (Point1-Point2) × (Point0-Point2)
perpendicular1 = perpendicular0*(radius of cone)/|perpendicular0|
perpendicular2 = perpendicular0 × (Point1-Point2) / |Point1-Point2|
pontx = point2+(point1-point2)*(length of cone)/|Point1-Point2| + sin(x)*perpendicular1+cos(x)*perpendicular2


but I'm not sure what to do what a component of perpendicular0 is zero - then I'll get a divide by zero.


'a component of perpendicular0 is zero' is equivalent to 'point0 is on the line through point1 and point2'. That's why you pick a point not on that line. :)
ok dumb question, but is there some guaranteed way of picking a point not coliear to point 1 and 2?
Quote:Original post by markww
ok dumb question, but is there some guaranteed way of picking a point not coliear to point 1 and 2?
What you're really looking for here is a vector that is not collinear with the arrow direction vector (choosing a point not on the line is just a roundabout way of generating this vector).

One sure way to pick such a vector is to select the cardinal basis vector corresponding to the element of the direction vector with the least magnitude. Using this method you can generate a basis that is guaranteed to be valid, but the results may not be ideal, depending on the circumstances.

Another option is to use a fixed vector (say, the world up vector) in all cases other than when the direction vector is parallel or nearly parallel to this vector. This can give more consistent results in some cases.

Perhaps you could tell us a little more about the context. Will the arrow be in motion? Are there any constraints on its orientation?
Hi jyk,

I'd like to be able to use this with any two arbitrary points - just a general arrow class.

What do you mean by:

"but the results may not be ideal, depending on the circumstances."

does that mean that the base points of the arrow head generated will be 'right' but come out looking.. funky?

Thanks
Quote:Original post by markww
Hi jyk,

I'd like to be able to use this with any two arbitrary points - just a general arrow class.

What do you mean by:

"but the results may not be ideal, depending on the circumstances."

does that mean that the base points of the arrow head generated will be 'right' but come out looking.. funky?
It will always look 'right'. The problem with the element-of-least-magnitude approach is that if the arrow is in motion, the arrowhead may 'snap' between two orientations suddenly (this happens when the cardinal basis vector selected to generate the initial cross product changes).

If you use a fixed vector instead, the orientation of the arrowhead should change smoothly, more or less, as the arrow moves. The only problem as that you then have to handle the case where the arrow direction vector is parallel or nearly parallel to this fixed vector separately.

Another option would be to create an initial (complete) orientation for your arrow, and then update it incrementally as you go. Again though, what method will work best depends on what exactly the arrow will be doing (remaining stationary, translating but not rotating, flying through the air, etc.).

This topic is closed to new replies.

Advertisement