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 * -------------------------------------------------------------------------*/
10 /* #include "macros.h" */
12 /* -------------------------- Static Routines ---------------------------- */
14 /* ------------------------- Internal Routines --------------------------- */
16 /* -------------------------- Public Routines ---------------------------- */
20 * Sets a matrix to identity.
24 MAT3identity (register MAT3mat mat)
28 bzero (mat, sizeof(MAT3mat));
29 for (i = 0; i < 4; i++)
34 * Sets a matrix to zero.
38 MAT3zero (MAT3mat mat)
40 bzero (mat, sizeof(MAT3mat));
45 * Copies one matrix to another.
49 MAT3copy(MAT3mat to, MAT3mat from)
51 bcopy (from, to, sizeof(MAT3mat));
55 * This multiplies two matrices, producing a third, which may the same as
56 * either of the first two.
60 MAT3mult (result_mat, mat1, mat2)
62 register MAT3mat mat1, mat2;
67 for (i = 0; i < 4; i++)
68 for (j = 0; j < 4; j++)
69 tmp_mat[i][j] = (mat1[i][0] * mat2[0][j] +
70 mat1[i][1] * mat2[1][j] +
71 mat1[i][2] * mat2[2][j] +
72 mat1[i][3] * mat2[3][j]);
73 MAT3copy (result_mat, tmp_mat);
77 * This returns the transpose of a matrix. The result matrix may be
78 * the same as the one to transpose.
82 MAT3transpose (result_mat, mat)
89 for (i = 0; i < 4; i++)
90 for (j = 0; j < 4; j++)
91 tmp_mat[i][j] = mat[j][i];
93 MAT3copy (result_mat, tmp_mat);
98 * This prints the given matrix to the given file pointer.
106 MAT3print_formatted(mat, fp, CNULL, CNULL, CNULL, CNULL);
110 * This prints the given matrix to the given file pointer.
111 * use the format string to pass to fprintf. head and tail
112 * are printed at the beginning and end of each line.
116 MAT3print_formatted(mat, fp, title, head, format, tail)
119 char *title, *head, *format, *tail;
123 /* This is to allow this to be called easily from a debugger */
124 if (fp == NULL) fp = stderr;
126 if (title == NULL) title = "MAT3 matrix:\n";
127 if (head == NULL) head = " ";
128 if (format == NULL) format = "%#8.4lf ";
129 if (tail == NULL) tail = "\n";
131 (void) fprintf(fp, title);
133 for (i = 0; i < 4; i++) {
134 (void) fprintf(fp, head);
135 for (j = 0; j < 4; j++) (void) fprintf(fp, format, mat[i][j]);
136 (void) fprintf(fp, tail);