1 /* #include "HEADERS.h" */
2 /* Copyright 1988, Brown Computer Graphics Group. All Rights Reserved. */
4 /* --------------------------------------------------------------------------
5 * This file contains routines that operate solely on matrices.
6 * -------------------------------------------------------------------------*/
11 /* #include "macros.h" */
13 /* -------------------------- Static Routines ---------------------------- */
15 /* ------------------------- Internal Routines --------------------------- */
17 /* -------------------------- Public Routines ---------------------------- */
21 * Sets a matrix to identity.
25 MAT3identity (register MAT3mat mat)
29 bzero (mat, sizeof(MAT3mat));
30 for (i = 0; i < 4; i++)
35 * Sets a matrix to zero.
39 MAT3zero (MAT3mat mat)
41 bzero (mat, sizeof(MAT3mat));
46 * Copies one matrix to another.
50 MAT3copy(MAT3mat to, MAT3mat from)
52 bcopy (from, to, sizeof(MAT3mat));
56 * This multiplies two matrices, producing a third, which may the same as
57 * either of the first two.
61 MAT3mult (result_mat, mat1, mat2)
63 register MAT3mat mat1, mat2;
68 for (i = 0; i < 4; i++)
69 for (j = 0; j < 4; j++)
70 tmp_mat[i][j] = (mat1[i][0] * mat2[0][j] +
71 mat1[i][1] * mat2[1][j] +
72 mat1[i][2] * mat2[2][j] +
73 mat1[i][3] * mat2[3][j]);
74 MAT3copy (result_mat, tmp_mat);
78 * This returns the transpose of a matrix. The result matrix may be
79 * the same as the one to transpose.
83 MAT3transpose (result_mat, mat)
90 for (i = 0; i < 4; i++)
91 for (j = 0; j < 4; j++)
92 tmp_mat[i][j] = mat[j][i];
94 MAT3copy (result_mat, tmp_mat);
99 * This prints the given matrix to the given file pointer.
107 MAT3print_formatted(mat, fp, CNULL, CNULL, CNULL, CNULL);
111 * This prints the given matrix to the given file pointer.
112 * use the format string to pass to fprintf. head and tail
113 * are printed at the beginning and end of each line.
117 MAT3print_formatted(mat, fp, title, head, format, tail)
120 char *title, *head, *format, *tail;
124 /* This is to allow this to be called easily from a debugger */
125 if (fp == NULL) fp = stderr;
127 if (title == NULL) title = "MAT3 matrix:\n";
128 if (head == NULL) head = " ";
129 if (format == NULL) format = "%#8.4lf ";
130 if (tail == NULL) tail = "\n";
132 (void) fprintf(fp, title);
134 for (i = 0; i < 4; i++) {
135 (void) fprintf(fp, head);
136 for (j = 0; j < 4; j++) (void) fprintf(fp, format, mat[i][j]);
137 (void) fprintf(fp, tail);