1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: xform.cpp,v 1.1 2000/06/19 02:58:08 kevin Exp $
7 ** This program is free software; you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License (version 2) as
9 ** published by the Free Software Foundation.
11 ** This program is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
16 ** You should have received a copy of the GNU General Public License
17 ** along with this program; if not, write to the Free Software
18 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ******************************************************************************/
24 * rotate2d Rotates an array of 2 dimensional vectors
27 * rotate2d (x, y, n, angle)
28 * double x[], y[] Array of points
29 * int n Number of points in array
30 * double angle Rotation angle (counter-clockwise)
34 rotate2d (double x[], double y[], int n, double angle)
36 double cos_theta = cos (angle);
37 double sin_theta = sin (angle);
39 for (int i = 0; i < n; i++) {
40 double xrot = x[i] * cos_theta - y[i] * sin_theta;
41 double yrot = x[i] * sin_theta + y[i] * cos_theta;
49 * xlat2d Translates an array of 2 dimensional vectors
52 * xlat2d (x, y, n, xoffset, yoffset)
53 * double x[], y[] Array of points
54 * int n Number of points in array
55 * double xoffset, yoffset Offset to translate points by
59 xlat2d (double x[], double y[], int n, double xoffset, double yoffset)
61 for (int i = 0; i < n; i++) {
69 * scale2d Scale an array of 2 dimensional vectors
72 * scale2d (x, y, n, xoffset, yoffset)
73 * double x[], y[] Array of points
74 * int n Number of points in array
75 * double xfact, yfact x & y scaling factors
79 scale2d (double x[], double y[], int n, double xfact, double yfact)
81 for (int i = 0; i < n; i++) {
89 indent_mtx2 (GRFMTX_2D m)
91 m[0][0] = 1.0; m[0][1] = 0.0; m[0][2] = 0.0;
92 m[1][0] = 0.0; m[1][1] = 1.0; m[1][2] = 0.0;
93 m[2][0] = 0.0; m[2][1] = 0.0; m[2][2] = 1.0;
97 xlat_mtx2 (GRFMTX_2D m, const double x, const double y)
105 scale_mtx2 (GRFMTX_2D m, const double sx, const double sy)
113 rot_mtx2 (GRFMTX_2D m, const double theta)
115 double c = cos(theta);
116 double s = sin(theta);
119 m[0][0] = c; m[0][1] = s;
120 m[1][0] = -s; m[1][1] = c;
124 mult_mtx2 (GRFMTX_2D m1, GRFMTX_2D m2, GRFMTX_2D result)
128 for (int row = 0; row < 3; row++)
129 for (int col = 0; col < 3; col++) {
131 for (int calc = 0; calc < 3; calc++)
132 temp[row][col] += m1[row][calc] * m2[calc][col];
135 for (int row = 0; row < 3; row++)
136 for (int col = 0; col < 3; col++)
137 result[row][col] = temp[row][col];
141 xform_mtx2 (GRFMTX_2D m, double& x, double& y)
143 double xt = x * m[0][0] + y * m[1][0] + m[2][0];
144 double yt = x * m[0][1] + y * m[1][1] + m[2][1];