[GRASS-dev] symbol rotation is go
Glynn Clements
glynn at gclements.plus.com
Thu Apr 26 12:56:19 EDT 2007
Hamish wrote:
> I have just added a new libgis function: G_rotate_around_pt() in 6.3cvs.
> (make distclean, yet again)
>
> It rotates a point around a given center coord by a given angle.
I would suggest an alternate version:
void G_rotate_around_point(double X0, double Y0, double *X1, double *Y1, double angle)
{
double dx = *X1 - X0;
double dy = *X1 - X0;
double c = cos(D2R(angle));
double s = sin(D2R(angle));
double dx1 = dx * c - dy * s;
double dy1 = dx * s + dy * c;
*X1 = X0 + dx1;
*Y1 = Y0 + dy1;
}
Differences:
1. Uses double for coordinates instead of int.
2. Doesn't have a singularity at (X0,Y0) (atan2(0,0) may return NaN in
some implementations).
3. "void" return type; functions returning a meaningless "int" is
usually a hold-over from pre-ANSI C.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list