ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/freemol/trunk/smi23d/src/mengine/matrix.c
Revision: 3
Committed: Mon Jun 9 21:38:26 2008 UTC (11 years, 4 months ago) by tjod
File size: 3618 byte(s)
Log Message:
test

Line File contents
1 #define EXTERN extern
2
3 #include "pcwin.h"
4 #include "pcmod.h"
5
6 void matident(float (*)[4]);
7 void matrotsc(float (*)[4], int, float, float);
8 void matrotat(float (*)[4], int, float);
9 void mattrans(float (*)[4], float, float, float);
10 void matriply(float (*)[4], float (*)[4], float (*)[4]);
11 void matxform(float (*)[4], int);
12
13 /* -------------------------------------- */
14 void matident(float matrix[][4])
15 {
16 int i, j;
17
18 for( i = 0; i < 4; i++ )
19 {
20 for( j = 0; j < 4; j++ )
21 {
22 if( i == j )
23 matrix[j][i] = 1.;
24 else
25 matrix[j][i] = 0.;
26 }
27 }
28 return;
29 }
30 /* -------------------------------------- */
31 void matrotsc(float matrix[][4],int iaxis,float sine,float cose)
32 {
33
34 matident( matrix );
35 if( iaxis == 1 ){
36 matrix[1][1] = cose;
37 matrix[2][1] = sine;
38 matrix[1][2] = -sine;
39 matrix[2][2] = cose;
40 }
41 else if( iaxis == 2 ){
42 matrix[0][0] = cose;
43 matrix[2][0] = -sine;
44 matrix[0][2] = sine;
45 matrix[2][2] = cose;
46 }
47 else if( iaxis == 3 ){
48 matrix[0][0] = cose;
49 matrix[1][0] = sine;
50 matrix[0][1] = -sine;
51 matrix[1][1] = cose;
52 }
53 return;
54 }
55 /* -------------------------------------- */
56 void matrotat(float matrix[][4],int iaxis,float angle)
57 {
58 float cose, sine;
59
60 matident( matrix );
61 sine = sin( -angle*0.017453 );
62 cose = cos( -angle*0.017453 );
63 if( iaxis == 1 ){
64 matrix[1][1] = cose;
65 matrix[2][1] = sine;
66 matrix[1][2] = -sine;
67 matrix[2][2] = cose;
68 }
69 else if( iaxis == 2 ){
70 matrix[0][0] = cose;
71 matrix[2][0] = -sine;
72 matrix[0][2] = sine;
73 matrix[2][2] = cose;
74 }
75 else if( iaxis == 3 ){
76 matrix[0][0] = cose;
77 matrix[1][0] = sine;
78 matrix[0][1] = -sine;
79 matrix[1][1] = cose;
80 }
81 return;
82 }
83 /* -------------------------------------- */
84 void mattrans(float matrix[][4],float x,float y,float z)
85 {
86
87 matident( matrix );
88 matrix[0][3] = x;
89 matrix[1][3] = y;
90 matrix[2][3] = z;
91 return;
92 }
93 /* -------------------------------------- */
94 void matriply(float m1[][4],float m2[][4],float m3[][4])
95 {
96 int i, j, k;
97
98 for( i = 0; i < 4; i++ ){
99 for( j = 0; j < 4; j++ ){
100 m3[j][i] = 0.;
101 for( k = 0; k < 4; k++ ){
102 m3[j][i] = m3[j][i] + m1[k][i]*m2[j][k];
103 }
104 }
105 }
106 return;
107 }
108 /* -------------------------------------- */
109 void matxform(float matrix[][4],int issnum)
110 {
111 int i, k;
112 long int mask;
113 float x1[3];
114
115 mask = 0;
116 if (issnum != -1)
117 mask = 1L << issnum;
118
119 for( i = 1; i <= natom; i++ )
120 {
121 if ( (atom[i].substr[0] & mask) || issnum == -1)
122 {
123 for( k = 0; k < 3; k++ )
124 {
125 x1[k] = atom[i].x*matrix[k][0] + atom[i].y*matrix[k][1] + atom[i].z*
126 matrix[k][2] + matrix[k][3];
127 }
128 atom[i].x = x1[0];
129 atom[i].y = x1[1];
130 atom[i].z = x1[2];
131 }
132 }
133 return;
134 }