GRASS Programmer's Manual  6.4.2(2012)
icon.c
Go to the documentation of this file.
00001 
00017 #include <stdlib.h>
00018 #include <math.h>
00019 #include <grass/gis.h>
00020 
00021 static void trans(double *x, double *y, int n_points,
00022                   double angle, double scale, double xc, double yc)
00023 {
00024     double m[2][2];
00025     double sin_a = sin(angle);
00026     double cos_a = cos(angle);
00027     int i;
00028 
00029     m[0][0] = cos_a * scale;
00030     m[0][1] = -sin_a * scale;
00031     m[1][0] = sin_a * scale;
00032     m[1][1] = cos_a * scale;
00033 
00034     for (i = 0; i < n_points; i++) {
00035         double xi = x[i];
00036         double yi = y[i];
00037 
00038         x[i] = m[0][0] * xi + m[0][1] * yi + xc;
00039         y[i] = m[1][0] * xi + m[1][1] * yi + yc;
00040     }
00041 }
00042 
00053 int G_plot_icon(double xc, double yc, int type, double angle, double scale)
00054 {
00055     int i, np = 0;
00056     double x[10], y[10];
00057 
00058     G_debug(2, "G_plot_icon(): xc=%g, yc=%g", xc, yc);
00059 
00060     /* diamond, box */
00061     switch (type) {
00062     case G_ICON_CROSS:
00063         x[0] = -0.5;
00064         y[0] = 0.0;
00065         x[1] = 0.5;
00066         y[1] = 0.0;
00067         x[2] = 0.0;
00068         y[2] = -0.5;
00069         x[3] = 0.0;
00070         y[3] = 0.5;
00071         np = 4;
00072         break;
00073     case G_ICON_BOX:
00074         G_debug(1, "box");
00075         x[0] = -0.5;
00076         y[0] = -0.5;
00077         x[1] = 0.5;
00078         y[1] = -0.5;
00079         x[2] = 0.5;
00080         y[2] = -0.5;
00081         x[3] = 0.5;
00082         y[3] = 0.5;
00083         x[4] = 0.5;
00084         y[4] = 0.5;
00085         x[5] = -0.5;
00086         y[5] = 0.5;
00087         x[6] = -0.5;
00088         y[6] = 0.5;
00089         x[7] = -0.5;
00090         y[7] = -0.5;
00091         np = 8;
00092         break;
00093     case G_ICON_ARROW:
00094         x[0] = -1;
00095         y[0] = 0.5;
00096         x[1] = 0;
00097         y[1] = 0.0;
00098         x[2] = -1;
00099         y[2] = -0.5;
00100         x[3] = 0;
00101         y[3] = 0.0;
00102         np = 4;
00103         break;
00104     }
00105 
00106     trans(x, y, np, angle, scale, xc, yc);
00107 
00108     for (i = 0; i < np; i += 2)
00109         G_plot_line(x[i], y[i], x[i + 1], y[i + 1]);
00110 
00111     return (1);
00112 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines