1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: ctm.cpp,v 1.2 2000/06/19 19:04:05 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 ******************************************************************************/
21 /*-----------------------------------------------------------------------------
25 * Function: Current Transform Matrix routine for graphic library
26 * Programmer: Kevin Rosenberg
27 * Date Started: 1-22-85
35 * ctm_rotate_post_2 ()
38 * The indices on the 2d matrix are opposite of the cartesian order used
39 * in the sdf_2d files. Here, the 1st index is the row & and 2nd is the
41 *---------------------------------------------------------------------------*/
43 #include "ctsupport.h"
48 /*---------------------------------------------------------------------------*/
49 /* Geometric Operations */
50 /*---------------------------------------------------------------------------*/
53 ctm_xlat_pre_2 (double x, double y)
57 xlat_gmtx_2 (m, x, y);
63 ctm_xlat_post_2 (double x, double y)
67 xlat_gmtx_2 (m, x, y);
73 ctm_scale_pre_2 (double sx, double sy)
77 scale_gmtx_2 (m, sx, sy);
83 ctm_scale_post_2 (double sx, double sy)
87 scale_gmtx_2 (m, sx, sy);
93 ctm_rotate_pre_2 (double theta)
97 rotate_gmtx_2 (m, theta);
103 ctm_rotate_post_2 (double theta)
107 rotate_gmtx_2 (m, theta);
113 ctm_shear_pre_2 (double shrx, double shry)
117 shear_gmtx_2 (m, shrx, shry);
123 ctm_shear_post_2 (double shrx, double shry)
127 shear_gmtx_2 (m, shrx, shry);
131 /*---------------------------------------------------------------------------*/
132 /* Low-Level Internal Functions */
133 /*---------------------------------------------------------------------------*/
137 xlat_gmtx_2 (GRFMTX_2D m, double x, double y)
146 scale_gmtx_2 (GRFMTX_2D m, double sx, double sy)
155 shear_gmtx_2 (GRFMTX_2D m, double shrx, double shry)
163 rotate_gmtx_2 (GRFMTX_2D m, double theta)
172 m[0][0] = c; m[0][1] = s;
173 m[1][0] = -s; m[1][1] = c;
178 ident_gmtx_2 (GRFMTX_2D m)
180 m[0][0] = 1.; m[0][1] = 0.; m[0][2] = 0.;
181 m[1][0] = 0.; m[1][1] = 1.; m[1][2] = 0.;
182 m[2][0] = 0.; m[2][1] = 0.; m[2][2] = 1.;
187 mult_gmtx_2 (GRFMTX_2D a, GRFMTX_2D b, GRFMTX_2D c)
191 for (row = 0; row < 3; row++)
192 for (col = 0; col < 3; col++) {
194 for (calc = 0; calc < 3; calc++)
195 c[row][col] += a[row][calc] * b[calc][col];
200 invert_gmtx_2 (GRFMTX_2D a, GRFMTX_2D b)
204 determ = determ_gmtx_2 (a);
205 if (fabs(determ) < 1E-6)
206 sys_error (ERR_WARNING, "Determinant = %lg [invert_gmtx_2]", determ);
208 b[0][0] = (a[1][1] * a[2][2] - a[2][1] * a[1][2]) / determ;
209 b[1][0] = -(a[1][0] * a[2][2] - a[2][0] * a[1][2]) / determ;
210 b[2][0] = (a[1][0] * a[2][1] - a[2][0] * a[1][1]) / determ;
212 b[0][1] = -(a[0][1] * a[2][2] - a[2][1] * a[0][2]) / determ;
213 b[1][1] = (a[0][0] * a[2][2] - a[2][0] * a[0][2]) / determ;
214 b[2][1] = -(a[0][0] * a[2][1] - a[2][0] * a[0][1]) / determ;
216 b[0][2] = (a[0][1] * a[1][2] - a[1][1] * a[0][2]) / determ;
217 b[1][2] = -(a[0][0] * a[1][2] - a[1][0] * a[0][2]) / determ;
218 b[2][2] = (a[0][0] * a[1][1] - a[1][0] * a[0][1]) / determ;
223 determ_gmtx_2 (GRFMTX_2D a)
226 (a[0][0] * a[1][1] * a[2][2] - a[0][0] * a[2][1] * a[1][2] -
227 a[0][1] * a[1][0] * a[2][2] + a[0][1] * a[2][0] * a[1][2] +
228 a[0][2] * a[1][0] * a[2][1] - a[0][2] * a[2][0] * a[1][1]);