Jump to content
  • Advertisement
Sign in to follow this  
markww

drawing an arrow

This topic is 4267 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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. :)

Share this post


Link to post
Share on other sites
ok dumb question, but is there some guaranteed way of picking a point not coliear to point 1 and 2?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!