GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
icon.c
Go to the documentation of this file.
1 
17 #include <stdlib.h>
18 #include <math.h>
19 #include <grass/gis.h>
20 
21 static void trans(double *x, double *y, int n_points,
22  double angle, double scale, double xc, double yc)
23 {
24  double m[2][2];
25  double sin_a = sin(angle);
26  double cos_a = cos(angle);
27  int i;
28 
29  m[0][0] = cos_a * scale;
30  m[0][1] = -sin_a * scale;
31  m[1][0] = sin_a * scale;
32  m[1][1] = cos_a * scale;
33 
34  for (i = 0; i < n_points; i++) {
35  double xi = x[i];
36  double yi = y[i];
37 
38  x[i] = m[0][0] * xi + m[0][1] * yi + xc;
39  y[i] = m[1][0] * xi + m[1][1] * yi + yc;
40  }
41 }
42 
53 int G_plot_icon(double xc, double yc, int type, double angle, double scale)
54 {
55  int i, np = 0;
56  double x[10], y[10];
57 
58  G_debug(2, "G_plot_icon(): xc=%g, yc=%g", xc, yc);
59 
60  /* diamond, box */
61  switch (type) {
62  case G_ICON_CROSS:
63  x[0] = -0.5;
64  y[0] = 0.0;
65  x[1] = 0.5;
66  y[1] = 0.0;
67  x[2] = 0.0;
68  y[2] = -0.5;
69  x[3] = 0.0;
70  y[3] = 0.5;
71  np = 4;
72  break;
73  case G_ICON_BOX:
74  G_debug(1, "box");
75  x[0] = -0.5;
76  y[0] = -0.5;
77  x[1] = 0.5;
78  y[1] = -0.5;
79  x[2] = 0.5;
80  y[2] = -0.5;
81  x[3] = 0.5;
82  y[3] = 0.5;
83  x[4] = 0.5;
84  y[4] = 0.5;
85  x[5] = -0.5;
86  y[5] = 0.5;
87  x[6] = -0.5;
88  y[6] = 0.5;
89  x[7] = -0.5;
90  y[7] = -0.5;
91  np = 8;
92  break;
93  case G_ICON_ARROW:
94  x[0] = -1;
95  y[0] = 0.5;
96  x[1] = 0;
97  y[1] = 0.0;
98  x[2] = -1;
99  y[2] = -0.5;
100  x[3] = 0;
101  y[3] = 0.0;
102  np = 4;
103  break;
104  }
105 
106  trans(x, y, np, angle, scale, xc, yc);
107 
108  for (i = 0; i < np; i += 2)
109  G_plot_line(x[i], y[i], x[i + 1], y[i + 1]);
110 
111  return (1);
112 }
int G_plot_icon(double xc, double yc, int type, double angle, double scale)
Plot icon.
Definition: icon.c:53
struct transport * trans
Definition: com_io.c:143
int y
Definition: plot.c:34
int G_plot_line(double east1, double north1, double east2, double north2)
plot line between latlon coordinates
Definition: plot.c:230
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: gis/debug.c:51