drawing an arrow ?
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 ?
The answer might be in the post
''line from 2d vector...''
in the same forum (math)
did that answer your question!??
/Mankind gave birth to God.
''line from 2d vector...''
in the same forum (math)
did that answer your question!??
/Mankind gave birth to God.
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
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
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.
are you just drawing a line (arrow?)?
If yes, search for ''bresenham-line-drawing'' and similar stuff.
/Mankind gave birth to God.
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 !! }
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 !! }
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement