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

## 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 on other sites
Quote:
 I want to achieve this purely using the Math library..
What math library are you referring to?

##### Share on other sites
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 on other sites
Quote:
 Original post by fuzznetI 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 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 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.

-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 on other sites
Thanks..Let me look at it...I will be back

##### 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..

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633722
• Total Posts
3013550
×