#### Archived

This topic is now archived and is closed to further replies.

# drawing an arrow ?

## Recommended Posts

Hello, I want to write a function that draws me an arrow. something like this : drawarrow(px1,py1,qx2,qy2,arrow_degree) p / a / | / |/ /____b q p.. q.. are the coordinates of the main line (should be obvious) arrow_degree should be obvious too. but how can I compute the coords. of a and b ?

##### Share on other sites
The answer might be in the post
''line from 2d vector...''
in the same forum (math)

/Mankind gave birth to God.

##### Share on other sites
Your ASCII art got messed up. Next time put it in "code" tags. Because the spaces were removed, I may be misinterpreting your post.

The arrow is a vector. I assume you basically want the horizontal and vertical components?

For a coordinate system in which 0 is "North" and the degrees increase going clockwise, like in physics, then these equations express all of the relationships you should need to know:

deltaX = x1 - x2;
deltaY = y1 - y2;
magnitude = sqrt(deltaX2 + deltaY2);
angle = atan2(deltaY, deltaX);
xComponent = sin(angle) * magnitude;
yComponent = cos(angle) * magnitude;

For a coodinate system in which 0 is "East" and the degrees increase going counterclockwise, like in math, then you just need to switch the sine and cosine functions.

The points a and b you speak of will be (0, xComponent) and (yComponent, 0).

Edited by - TerranFury on October 16, 2001 6:22:01 PM

##### Share on other sites
forget my previous post! (it wasn''t exactly the same problem)

are you just drawing a line (arrow?)?
If yes, search for ''bresenham-line-drawing'' and similar stuff.

/Mankind gave birth to God.

##### Share on other sites
what API are u using ?? dx, openGL, win32 GDI ??

there are helper functions in GDI to draw lines.
dont need to learn the actual algorithm to draw a line,
just use the helper functions .

{ Stating the obvious never helped any situation !! }

• ### Forum Statistics

• Total Topics
628337
• Total Posts
2982164

• 9
• 24
• 9
• 9
• 13