1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: ctm.cpp,v 1.1 2000/06/19 18:05:03 kevin Exp $
7 ** Revision 1.1 2000/06/19 18:05:03 kevin
10 ** Revision 1.1 2000/06/13 16:20:31 kevin
11 ** finished c++ conversions
13 ** Revision 1.2 2000/05/11 14:07:23 kevin
14 ** Fixed compilation warnings
16 ** Revision 1.1.1.1 2000/04/28 13:02:44 kevin
17 ** Initial CVS import for first public release
21 ** This program is free software; you can redistribute it and/or modify
22 ** it under the terms of the GNU General Public License (version 2) as
23 ** published by the Free Software Foundation.
25 ** This program is distributed in the hope that it will be useful,
26 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
27 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 ** GNU General Public License for more details.
30 ** You should have received a copy of the GNU General Public License
31 ** along with this program; if not, write to the Free Software
32 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 ******************************************************************************/
35 /*-----------------------------------------------------------------------------
39 * Function: Current Transform Matrix routine for graphic library
40 * Programmer: Kevin Rosenberg
41 * Date Started: 1-22-85
49 * ctm_rotate_post_2 ()
52 * The indices on the 2d matrix are opposite of the cartesian order used
53 * in the sdf_2d files. Here, the 1st index is the row & and 2nd is the
55 *---------------------------------------------------------------------------*/
63 /*---------------------------------------------------------------------------*/
64 /* Geometric Operations */
65 /*---------------------------------------------------------------------------*/
68 ctm_xlat_pre_2 (double x, double y)
72 xlat_gmtx_2 (m, x, y);
78 ctm_xlat_post_2 (double x, double y)
82 xlat_gmtx_2 (m, x, y);
88 ctm_scale_pre_2 (double sx, double sy)
92 scale_gmtx_2 (m, sx, sy);
98 ctm_scale_post_2 (double sx, double sy)
102 scale_gmtx_2 (m, sx, sy);
108 ctm_rotate_pre_2 (double theta)
112 rotate_gmtx_2 (m, theta);
118 ctm_rotate_post_2 (double theta)
122 rotate_gmtx_2 (m, theta);
128 ctm_shear_pre_2 (double shrx, double shry)
132 shear_gmtx_2 (m, shrx, shry);
138 ctm_shear_post_2 (double shrx, double shry)
142 shear_gmtx_2 (m, shrx, shry);
146 /*---------------------------------------------------------------------------*/
147 /* Low-Level Internal Functions */
148 /*---------------------------------------------------------------------------*/
152 xlat_gmtx_2 (GRFMTX_2D m, double x, double y)
161 scale_gmtx_2 (GRFMTX_2D m, double sx, double sy)
170 shear_gmtx_2 (GRFMTX_2D m, double shrx, double shry)
178 rotate_gmtx_2 (GRFMTX_2D m, double theta)
187 m[0][0] = c; m[0][1] = s;
188 m[1][0] = -s; m[1][1] = c;
193 ident_gmtx_2 (GRFMTX_2D m)
195 m[0][0] = 1.; m[0][1] = 0.; m[0][2] = 0.;
196 m[1][0] = 0.; m[1][1] = 1.; m[1][2] = 0.;
197 m[2][0] = 0.; m[2][1] = 0.; m[2][2] = 1.;
202 mult_gmtx_2 (GRFMTX_2D a, GRFMTX_2D b, GRFMTX_2D c)
206 for (row = 0; row < 3; row++)
207 for (col = 0; col < 3; col++) {
209 for (calc = 0; calc < 3; calc++)
210 c[row][col] += a[row][calc] * b[calc][col];
215 invert_gmtx_2 (GRFMTX_2D a, GRFMTX_2D b)
219 determ = determ_gmtx_2 (a);
220 if (fabs(determ) < 1E-6)
221 sys_error (ERR_WARNING, "Determinant = %lg [invert_gmtx_2]", determ);
223 b[0][0] = (a[1][1] * a[2][2] - a[2][1] * a[1][2]) / determ;
224 b[1][0] = -(a[1][0] * a[2][2] - a[2][0] * a[1][2]) / determ;
225 b[2][0] = (a[1][0] * a[2][1] - a[2][0] * a[1][1]) / determ;
227 b[0][1] = -(a[0][1] * a[2][2] - a[2][1] * a[0][2]) / determ;
228 b[1][1] = (a[0][0] * a[2][2] - a[2][0] * a[0][2]) / determ;
229 b[2][1] = -(a[0][0] * a[2][1] - a[2][0] * a[0][1]) / determ;
231 b[0][2] = (a[0][1] * a[1][2] - a[1][1] * a[0][2]) / determ;
232 b[1][2] = -(a[0][0] * a[1][2] - a[1][0] * a[0][2]) / determ;
233 b[2][2] = (a[0][0] * a[1][1] - a[1][0] * a[0][1]) / determ;
238 determ_gmtx_2 (GRFMTX_2D a)
241 (a[0][0] * a[1][1] * a[2][2] - a[0][0] * a[2][1] * a[1][2] -
242 a[0][1] * a[1][0] * a[2][2] + a[0][1] * a[2][0] * a[1][2] +
243 a[0][2] * a[1][0] * a[2][1] - a[0][2] * a[2][0] * a[1][1]);