X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=libctgraphics%2Fctm.cpp;fp=libctgraphics%2Fctm.cpp;h=4f88c772debeb81cff0a07d28bdf75105e69bef4;hb=bf7295a63667dcca309389ee6dd5328a3a25f22b;hp=0000000000000000000000000000000000000000;hpb=1eb1fcf291b39a016864d78a4060e83cd9046437;p=ctsim.git diff --git a/libctgraphics/ctm.cpp b/libctgraphics/ctm.cpp new file mode 100644 index 0000000..4f88c77 --- /dev/null +++ b/libctgraphics/ctm.cpp @@ -0,0 +1,245 @@ +/***************************************************************************** +** This is part of the CTSim program +** Copyright (C) 1983-2000 Kevin Rosenberg +** +** $Id: ctm.cpp,v 1.1 2000/06/19 18:05:03 kevin Exp $ +** $Log: ctm.cpp,v $ +** Revision 1.1 2000/06/19 18:05:03 kevin +** initial cvs import +** +** Revision 1.1 2000/06/13 16:20:31 kevin +** finished c++ conversions +** +** Revision 1.2 2000/05/11 14:07:23 kevin +** Fixed compilation warnings +** +** Revision 1.1.1.1 2000/04/28 13:02:44 kevin +** Initial CVS import for first public release +** +** +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License (version 2) as +** published by the Free Software Foundation. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +******************************************************************************/ + +/*----------------------------------------------------------------------------- + * FILE IDENTIFICATION + * + * Name: ctm.c + * Function: Current Transform Matrix routine for graphic library + * Programmer: Kevin Rosenberg + * Date Started: 1-22-85 + * + * FUNCTION SUMMARY + * ctm_xlat_pre_2 () + * ctm_xlat_post_2 () + * ctm_scale_pre_2 () + * ctm_scale_post_2 () + * ctm_rotate_pre_2 () + * ctm_rotate_post_2 () + * + * NOTES + * The indices on the 2d matrix are opposite of the cartesian order used + * in the sdf_2d files. Here, the 1st index is the row & and 2nd is the + * column + *---------------------------------------------------------------------------*/ + +#include "kstddef.h" +#include +#include "kmath.h" +#include "sgp.h" + + +/*---------------------------------------------------------------------------*/ +/* Geometric Operations */ +/*---------------------------------------------------------------------------*/ + +void +ctm_xlat_pre_2 (double x, double y) +{ + GRFMTX_2D m; + + xlat_gmtx_2 (m, x, y); + ctm_pre_mult_2 (m); +} + + +void +ctm_xlat_post_2 (double x, double y) +{ + GRFMTX_2D m; + + xlat_gmtx_2 (m, x, y); + ctm_post_mult_2 (m); +} + + +void +ctm_scale_pre_2 (double sx, double sy) +{ + GRFMTX_2D m; + + scale_gmtx_2 (m, sx, sy); + ctm_pre_mult_2 (m); +} + + +void +ctm_scale_post_2 (double sx, double sy) +{ + GRFMTX_2D m; + + scale_gmtx_2 (m, sx, sy); + ctm_post_mult_2 (m); +} + + +void +ctm_rotate_pre_2 (double theta) +{ + GRFMTX_2D m; + + rotate_gmtx_2 (m, theta); + ctm_pre_mult_2 (m); +} + + +void +ctm_rotate_post_2 (double theta) +{ + GRFMTX_2D m; + + rotate_gmtx_2 (m, theta); + ctm_post_mult_2 (m); +} + + +void +ctm_shear_pre_2 (double shrx, double shry) +{ + GRFMTX_2D m; + + shear_gmtx_2 (m, shrx, shry); + ctm_pre_mult_2 (m); +} + + +void +ctm_shear_post_2 (double shrx, double shry) +{ + GRFMTX_2D m; + + shear_gmtx_2 (m, shrx, shry); + ctm_post_mult_2 (m); +} + +/*---------------------------------------------------------------------------*/ +/* Low-Level Internal Functions */ +/*---------------------------------------------------------------------------*/ + + +void +xlat_gmtx_2 (GRFMTX_2D m, double x, double y) +{ + ident_gmtx_2 (m); + m[2][0] = x; + m[2][1] = y; +} + + +void +scale_gmtx_2 (GRFMTX_2D m, double sx, double sy) +{ + ident_gmtx_2 (m); + m[0][0] = sx; + m[1][1] = sy; +} + + +void +shear_gmtx_2 (GRFMTX_2D m, double shrx, double shry) +{ + ident_gmtx_2 (m); + m[1][0] = shrx; + m[0][1] = shry; +} + +void +rotate_gmtx_2 (GRFMTX_2D m, double theta) +{ + double s, c; + + s = sin (theta); + c = cos (theta); + + ident_gmtx_2 (m); + + m[0][0] = c; m[0][1] = s; + m[1][0] = -s; m[1][1] = c; +} + + +void +ident_gmtx_2 (GRFMTX_2D m) +{ + m[0][0] = 1.; m[0][1] = 0.; m[0][2] = 0.; + m[1][0] = 0.; m[1][1] = 1.; m[1][2] = 0.; + m[2][0] = 0.; m[2][1] = 0.; m[2][2] = 1.; +} + + +void +mult_gmtx_2 (GRFMTX_2D a, GRFMTX_2D b, GRFMTX_2D c) +{ + int row, col, calc; + + for (row = 0; row < 3; row++) + for (col = 0; col < 3; col++) { + c[row][col] = 0.; + for (calc = 0; calc < 3; calc++) + c[row][col] += a[row][calc] * b[calc][col]; + } +} + +void +invert_gmtx_2 (GRFMTX_2D a, GRFMTX_2D b) +{ + double determ; + + determ = determ_gmtx_2 (a); + if (fabs(determ) < 1E-6) + sys_error (ERR_WARNING, "Determinant = %lg [invert_gmtx_2]", determ); + + b[0][0] = (a[1][1] * a[2][2] - a[2][1] * a[1][2]) / determ; + b[1][0] = -(a[1][0] * a[2][2] - a[2][0] * a[1][2]) / determ; + b[2][0] = (a[1][0] * a[2][1] - a[2][0] * a[1][1]) / determ; + + b[0][1] = -(a[0][1] * a[2][2] - a[2][1] * a[0][2]) / determ; + b[1][1] = (a[0][0] * a[2][2] - a[2][0] * a[0][2]) / determ; + b[2][1] = -(a[0][0] * a[2][1] - a[2][0] * a[0][1]) / determ; + + b[0][2] = (a[0][1] * a[1][2] - a[1][1] * a[0][2]) / determ; + b[1][2] = -(a[0][0] * a[1][2] - a[1][0] * a[0][2]) / determ; + b[2][2] = (a[0][0] * a[1][1] - a[1][0] * a[0][1]) / determ; +} + + +double +determ_gmtx_2 (GRFMTX_2D a) +{ + return + (a[0][0] * a[1][1] * a[2][2] - a[0][0] * a[2][1] * a[1][2] - + a[0][1] * a[1][0] * a[2][2] + a[0][1] * a[2][0] * a[1][2] + + a[0][2] * a[1][0] * a[2][1] - a[0][2] * a[2][0] * a[1][1]); +} +