• Main Page
  • Related Pages
  • Data Structures
  • Files
  • File List
  • Globals

rotate.c

Go to the documentation of this file.
00001 
00015 #include <math.h>
00016 
00017 # define RpD ((2 * M_PI) / 360.)        /* radians/degree */
00018 # define D2R(d) (double)(d * RpD)       /* degrees->radians */
00019 # define R2D(d) (double)(d / RpD)       /* radians->degrees */
00020 
00021 
00022 
00035 void G_rotate_around_point(double X0, double Y0, double *X1, double *Y1,
00036                            double angle)
00037 {
00038     double dx = *X1 - X0;
00039     double dy = *Y1 - Y0;
00040     double c = cos(D2R(angle));
00041     double s = sin(D2R(angle));
00042     double dx1 = dx * c - dy * s;
00043     double dy1 = dx * s + dy * c;
00044 
00045     *X1 = X0 + dx1;
00046     *Y1 = Y0 + dy1;
00047 }
00048 
00062 void G_rotate_around_point_int(int X0, int Y0, int *X1, int *Y1, double angle)
00063 {
00064     double x = (double)*X1;
00065     double y = (double)*Y1;
00066 
00067     if (angle == 0.0)
00068         return;
00069 
00070     G_rotate_around_point((double)X0, (double)Y0, &x, &y, angle);
00071 
00072     *X1 = (int)floor(x + 0.5);
00073     *Y1 = (int)floor(y + 0.5);
00074 }

Generated on Wed Oct 13 2010 12:09:30 for GRASS Programmer's Manual by  doxygen 1.7.1