Jump to content
  • Advertisement
Sign in to follow this  
fuzznet

Drawing arrowheads

This topic is 4097 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 want to draw a closed arrowhead at one end of a line with two points(x1,y1)and (x2,y2). I want to achieve this purely using the Math library..Can anybody help me with an easier way of doing this? I dont even know how to draw a line perpendicular to an existing line..So a snippet would be better.. Thanks

Share this post


Link to post
Share on other sites
Advertisement
I am referring to the System.Math library in C#. I am working on a WPF Application project. It would be helpful if anyone could explain me the logic or provide me with a code snippet to draw arrowheads..

Thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by fuzznet
I am referring to the System.Math library in C#. I am working on a WPF Application project. It would be helpful if anyone could explain me the logic or provide me with a code snippet to draw arrowheads..
A typical approach would be to construct a transform representing the arrowhead position and orientation, and then use this transform to render an arrowhead 'model' (which, at its simplest, could be nothing more than a single triangle).

In local space, the model would most likely be situated with the point at the origin, oriented along one of the cardinal axes (+ or - x or y). The transform for the arrowhead would then be built with the normalized vector from the first point to the second point as one basis vector, a vector perpendicular to that as the second basis vector, and the endpoint itself as the translation.

You can compute a vector perpendicular to a vector (x,y) as (-y,x).

Share this post


Link to post
Share on other sites
or:

Arrow from A -> B

draw line from A to B

create vector pointing from B to A
normalize vector
scale vector to length of arrowhead size
rotate it X degrees clockwise & draw that line
rotate the base one X degrees counter-clockwise and draw that line

now you have an arrow that looks like this:

-->

to make the head a perfect triangle just skip the last 2 draw line calls and draw a triangle with those endpoints.

-me

Share this post


Link to post
Share on other sites
Hi,
I dont know how to create a transform???So I've ventured into vectors and this is where I have reached.
Can you verify please---

-To create an arrowhead at the Point B of an existing line(Point A(x1,y1),Point B(x2,y2))

1)create a vector pointing from B to A:
dx=x2-x1
dy=y2-y1

2)Normalize vector:
NV=1/Math.Sqrt(dx*dx+dy*dy)
dx *= NV
dy *= NV

3)What do you mean by scaling a vector to the size of an arrowhead? How do I rotate x degrees..
These two points were very confusing..Can you explain?
-Thanks

Share this post


Link to post
Share on other sites
Thanks for the tutorials. Ok so whatever I've done to create and normalize vectors is correct. I got how to scale a vector. But then how do I rotate the vector and find the three points inorder to draw a triangle..
Did I miss something in the tutorials?

Sorry I,ve just started with this project so bear with me..

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!