1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: kmath.h,v 1.8 2000/05/07 12:46:19 kevin Exp $
7 ** Revision 1.8 2000/05/07 12:46:19 kevin
10 ** Revision 1.7 2000/05/04 18:16:34 kevin
11 ** renamed filter definitions
13 ** Revision 1.6 2000/05/02 20:00:25 kevin
14 ** *** empty log message ***
16 ** Revision 1.5 2000/05/02 15:31:39 kevin
19 ** Revision 1.4 2000/04/30 19:17:35 kevin
20 ** Set up include files for conditional INTERACTIVE_GRAPHICS
22 ** Revision 1.3 2000/04/28 14:14:16 kevin
23 ** *** empty log message ***
26 ** This program is free software; you can redistribute it and/or modify
27 ** it under the terms of the GNU General Public License (version 2) as
28 ** published by the Free Software Foundation.
30 ** This program is distributed in the hope that it will be useful,
31 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
32 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 ** GNU General Public License for more details.
35 ** You should have received a copy of the GNU General Public License
36 ** along with this program; if not, write to the Free Software
37 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38 ******************************************************************************/
39 /******************************************************************************
42 * Header file containing definitions for numerical app's
43 * Date Started: Nov 84
45 *****************************************************************************/
55 #endif /* __cplusplus */
57 #define PI 3.14159265358979323846
58 #define HALFPI 1.57079632679489661923 /* PI divided by 2 */
59 #define QUARTPI 0.78539816339744830962 /* PI divided by 4 */
60 #define I_PI 0.31830988618379067154 /* Inverse of PI */
61 #define I_PID2 0.63661977236758134308 /* Inverse of PID2 */
63 #define TWOPI 6.28318530717958647692
64 #define SQRT2 1.414213562373095049
66 #define F_EPSILON 1.0E-6
67 #define D_EPSILON 1.0E-10
69 #define DEG_TO_RAD(x) (x*(PI/180.))
70 #define RAD_TO_DEG(x) (x*(180./PI))
73 #define ASSUMEDZERO 1E-10
75 /* codes for C data types */
84 typedef char *CMTX_1D;
85 typedef CMTX_1D *CMTX_2D;
86 typedef CMTX_2D *CMTX_3D;
89 typedef IMTX_1D *IMTX_2D;
90 typedef IMTX_2D *IMTX_3D;
92 typedef float *FMTX_1D;
93 typedef FMTX_1D *FMTX_2D;
94 typedef FMTX_2D *FMTX_3D;
96 typedef double *DMTX_1D;
97 typedef DMTX_1D *DMTX_2D;
98 typedef DMTX_2D *DMTX_3D;
100 typedef double GRFMTX_2D[3][3];
101 typedef double GRFMTX_3D[4][4];
103 union elem_val_un { /* holds an element value */
111 typedef union elem_val_un MTX_ELEM_VAL;
114 union elem_ptr_un { /* holds a pointer to a 1D vector of any type */
122 typedef union elem_ptr_un MTX_1D;
123 typedef MTX_1D *MTX_2D;
124 typedef MTX_2D *MTX_3D;
126 union mtx_val_ptr_un { /* pointer to matrix values */
132 typedef union mtx_val_ptr_un MTX_PTR;
135 unsigned int order; /* order, or dimension, of matrix */
136 unsigned int elemtype; /* element type */
137 unsigned int elemsize; /* size of element in bytes */
138 unsigned int nx, ny, nz; /* size of matrix in each dimension */
139 MTX_PTR val; /* pointer to matrix values */
142 typedef struct matrix_st MTX;
143 typedef struct matrix_st *MTXP;
145 /* DEFINITION IDENTIFICATION
147 * Definitions to access a matrix element from an matrix
151 (mtx->elemtype == DT_FLOAT ? mtx->val.m1.f[x] :\
152 (mtx->elemtype == DT_DOUBLE ? mtx->val.m1.d[x] :\
153 (mtx->elemtype == DT_INT ? mtx->val.m1.i[x] :\
154 (mtx->elemtype == DT_LONG ? mtx->val.m1.l[x] :\
155 (mtx->elemtype == DT_CHAR ? mtx->val.m1.c[x] :\
159 #define me2(mtx,x,y)\
160 (mtx->elemtype == DT_FLOAT ? mtx->val.m2[x].f[y] :\
161 (mtx->elemtype == DT_DOUBLE ? mtx->val.m2[x].d[y] :\
162 (mtx->elemtype == DT_INT ? mtx->val.m2[x].i[y] :\
163 (mtx->elemtype == DT_LONG ? mtx->val.m2[x].l[y] :\
164 (mtx->elemtype == DT_CHAR ? mtx->val.m2[x].c[y] :\
169 #define me3(mtx,x,y,z)\
170 (mtx->elemtype == DT_FLOAT ? mtx->val.m3[x][y].f[z] :\
171 (mtx->elemtype == DT_DOUBLE ? mtx->val.m3[x][y].d[z] :\
172 (mtx->elemtype == DT_INT ? mtx->val.m3[x][y].i[z] :\
173 (mtx->elemtype == DT_LONG ? mtx->val.m3[x][y].l[z] :\
174 (mtx->elemtype == DT_CHAR ? mtx->val.m3[x][y].c[z] :\
180 int clip_rect(double *x1, double *y1, double *x2, double *y2, const double rect[4]);
181 int clip_segment(double *x1, double *y1, double *x2, double *y2, const double u, const double v);
182 int clip_sector(double *x1, double *y1, double *x2, double *y2, const double u, const double v);
183 int clip_circle(double *x1, double *y1, double *x2, double *y2, const double cx, const double cy, const double radius, double t1, double t2);
184 int clip_triangle(double *x1, double *y1, double *x2, double *y2, const double u, const double v, const int clip_xaxis);
187 long int lnearest(double x);
190 double fmax(const double a, const double b);
191 void minmax_dvector(const double array[], const int pts, double *xmin, double *xmax);
194 void mtx_show(const MTX *mtx);
195 void mtx_prt(const MTX *mtx, FILE *fp);
196 int mtx_prt_elem(const MTX *mtx, FILE *fp, unsigned int x, unsigned int y, unsigned int z);
199 int mtx_get_elem(const MTX *mtx, MTX_ELEM_VAL *me, const int x, const int y, const int z);
200 int mtx_put_elem(MTX *mtx, const MTX_ELEM_VAL *me, unsigned int x, unsigned int y, unsigned int z);
203 int mtx_inp_elem(const char *prompt, MTX_ELEM_VAL *mev, const int dtype);
206 MTX *mtx_init(const unsigned int order, const unsigned int elem_type, const unsigned int nx, const unsigned int ny, const unsigned int nz);
207 MTX *mtx_clr(MTX *mtx);
208 int mtx_free(MTX *mtx);
209 int mtx_elem_size(const int dt);
210 int mtx_check(const MTX *mtx, const char *func_name);
213 double norm_ang(double theta);
216 double simpson(const double xmin, const double xmax, const double *y, const int np);
219 void indent_mtx2(GRFMTX_2D m);
220 void xlat_mtx2(GRFMTX_2D m, const double x, const double y);
221 void scale_mtx2(GRFMTX_2D m, const double sx, const double sy);
222 void rot_mtx2(GRFMTX_2D m, const double theta);
223 void mult_mtx2(GRFMTX_2D m1, GRFMTX_2D m2, GRFMTX_2D result);
224 void xform_mtx2(GRFMTX_2D const m, double *x, double *y);
225 void rotate2d(double x[], double y[], int pts, double angle);
226 void xlat2d(double x[], double y[], int pts, double xoffset, double yoffset);
227 void scale2d(double x[], double y[], int pts, double xfact, double yfact);
231 #endif /* __cplusplus */