GRASS 8 Programmer's Manual
8.6.0dev(2026)-4bb960b182
Loading...
Searching...
No Matches
rotate.c
Go to the documentation of this file.
1
/*!
2
* \file lib/gis/rotate.c
3
*
4
* \brief GIS Library - rotate
5
*
6
* SPDX-FileCopyrightText: 2001-2014 GRASS Development Team
7
* SPDX-License-Identifier: GPL-2.0-or-later
8
*
9
* \author Hamish Bowman, Glynn Clements
10
*/
11
12
#include <math.h>
13
14
#define RpD ((2 * M_PI) / 360.)
/* radians/degree */
15
#define D2R(d) (double)(d * RpD)
/* degrees->radians */
16
#define R2D(d) (double)(d / RpD)
/* radians->degrees */
17
18
/*!
19
* \brief Rotate point (double version)
20
*
21
* Given a point, angle, and origin, rotate the point around the origin
22
* by the given angle. Coordinates and results are double prec floating point.
23
*
24
* \param X0 X component of origin (center of circle)
25
* \param Y0 Y component of origin (center of circle)
26
* \param[out] X1 X component of point to be rotated (variable is modified!)
27
* \param[out] Y1 Y component of point to be rotated (variable is modified!)
28
* \param angle in degrees, measured CCW from east
29
*/
30
void
G_rotate_around_point
(
double
X0
,
double
Y0
,
double
*
X1
,
double
*
Y1
,
31
double
angle
)
32
{
33
double
dx = *
X1
-
X0
;
34
double
dy = *
Y1
-
Y0
;
35
double
c =
cos
(
D2R
(
angle
));
36
double
s =
sin
(
D2R
(
angle
));
37
double
dx1
= dx * c - dy * s;
38
double
dy1
= dx * s + dy * c;
39
40
*
X1
=
X0
+
dx1
;
41
*
Y1
=
Y0
+
dy1
;
42
}
43
44
/*!
45
* \brief Rotate point (int version)
46
*
47
* Given a point, angle, and origin, rotate the point around the origin
48
* by the given angle. Coordinates are given in integer and results are rounded
49
* back to integer.
50
*
51
* \param X0 X component of origin (center of circle)
52
* \param Y0 Y component of origin (center of circle)
53
* \param[out] X1 X component of point to be rotated (variable is modified!)
54
* \param[out] Y1 Y component of point to be rotated (variable is modified!)
55
* \param angle in degrees, measured CCW from east
56
*/
57
void
G_rotate_around_point_int
(
int
X0
,
int
Y0
,
int
*
X1
,
int
*
Y1
,
double
angle
)
58
{
59
double
x
= (
double
)*
X1
;
60
double
y = (
double
)*
Y1
;
61
62
if
(
angle
== 0.0)
63
return
;
64
65
G_rotate_around_point
((
double
)
X0
, (
double
)
Y0
, &
x
, &y,
angle
);
66
67
*
X1
= (
int
)
floor
(
x
+ 0.5);
68
*
Y1
= (
int
)
floor
(y + 0.5);
69
}
AMI_STREAM
Definition
ami_stream.h:153
D2R
#define D2R(d)
Definition
rotate.c:15
G_rotate_around_point_int
void G_rotate_around_point_int(int X0, int Y0, int *X1, int *Y1, double angle)
Rotate point (int version)
Definition
rotate.c:57
G_rotate_around_point
void G_rotate_around_point(double X0, double Y0, double *X1, double *Y1, double angle)
Rotate point (double version)
Definition
rotate.c:30
x
#define x
lib
gis
rotate.c
Generated on Sun Sep 13 2026 06:57:49 for GRASS 8 Programmer's Manual by
1.9.8