Tool to Draw Vectors as Arrows?

James Darrell McCauley mccauley at ecn.purdue.edu
Tue Jun 20 19:23:21 EDT 1995


John Talcott (talcott at trg.saic.com) writes on 20 June 1995:
>Does anyone know of a GRASS tool that will draw
>vector data (magnitude & direction) as arrows
>as an overlay to a raster layer? I know d.rast.arrow
>draws aspect direction as arrows and I need something
>similar. I couldn't find anything in the archives.
>Thanks for any help!

here's what I would do:

 Copy the d.vect source and modify:
   plot1.c: between lines 56 & 57
   plot2.c: between lines 74 & 75, 100 & 101
 Don't draw the last line segment of each Points struct.
 Create a G_plot_arrow (if one doesn't already exist).
 
Appended is a snippet from g.gnuplot that draws arrow heads
(a good start for a G_plot_arrow). It uses the angle of the
(last) line segment to figure out the direction of the arrow head.

Good luck,

Darrell
-- 
James Darrell McCauley, PhD             http://soils.ecn.purdue.edu/~mccauley/
Agricultural & Biological Engineering   mccauley at ecn.purdue.edu
Purdue University                       tel: 317.494.1198 fax: 317.496.1115

#define ROOT2 (1.41421)         /* sqrt of 2 */

do_arrow(sx, sy, ex, ey, head)
        int sx,sy;                      /* start point */
        int ex, ey;                     /* end point (point of arrowhead) */
        TBOOLEAN head;
{
    register struct termentry *t = &term_tbl[term];
    int len = (t->h_tic + t->v_tic)/2; /* arrowhead size = avg of tic sizes */

    /* draw the line for the arrow. That's easy. */
    (*t->move)(sx, sy);
    (*t->vector)(ex, ey);

    if (head) {
    /* now draw the arrow head. */
    /* we put the arrowhead marks at 45 degrees to line */
       if (sx == ex) {
           /* vertical line, special case */
              int delta = ((float)len / ROOT2 + 0.5);
              if (sy < ey)
                      delta = -delta;   /* up arrow goes the other way */
              (*t->move)(ex - delta, ey + delta);
              (*t->vector)(ex,ey);
              (*t->vector)(ex + delta, ey + delta);
       } else {
              int dx = sx - ex;
              int dy = sy - ey;
              double coeff = len / sqrt(2.0*((double)dx*(double)dx 
                                   + (double)dy*(double)dy));
              int x,y;                  /* one endpoint */

              x = (int)( ex + (dx + dy) * coeff );
              y = (int)( ey + (dy - dx) * coeff );
              (*t->move)(x,y);
              (*t->vector)(ex,ey);

              x = (int)( ex + (dx - dy) * coeff );
              y = (int)( ey + (dy + dx) * coeff );
              (*t->vector)(x,y);
       }
    }
}



More information about the grass-user mailing list