Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
CreateRotMat.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file CreateRotMat.c
5 
6  \version V1.6R
7  \date 27.09.95
8  \brief Simple matrix and vector operations
9 
10  \copyright (c) UCL / Dr. Andrew C. R. Martin 1991-5
11  \author Dr. Andrew C. R. Martin
12  \par
13  Institute of Structural & Molecular Biology,
14  University College London,
15  Gower Street,
16  London.
17  WC1E 6BT.
18  \par
19  andrew@bioinf.org.uk
20  andrew.martin@ucl.ac.uk
21 
22 **************************************************************************
23 
24  This code is NOT IN THE PUBLIC DOMAIN, but it may be copied
25  according to the conditions laid out in the accompanying file
26  COPYING.DOC.
27 
28  The code may be modified as required, but any modifications must be
29  documented so that the person responsible can be identified.
30 
31  The code may not be sold commercially or included as part of a
32  commercial product except as described in the file COPYING.DOC.
33 
34 **************************************************************************
35 
36  Description:
37  ============
38 
39 
40 **************************************************************************
41 
42  Usage:
43  ======
44 
45 **************************************************************************
46 
47  Revision History:
48  =================
49 - V1.0 06.09.91 Original
50 - V1.0a 01.06.92 Documented
51 - V1.1 30.09.92 Matrix multiplication added
52 - V1.2 10.06.93 void return from matrix multiplication
53 - V1.3 22.07.93 Added CreateRotMat()
54 - V1.4 03.08.93 Changed matrix multiplication to standard direction
55 - V1.5 28.07.95 Added VecDist()
56 - V1.6 27.09.95 Added MatMult33_33()
57 - V1.7 07.07.14 Use bl prefix for functions By: CTP
58 
59 *************************************************************************/
60 /* Doxygen
61  -------
62  #GROUP Maths
63  #SUBGROUP Matrices
64  #FUNCTION blCreateRotMat()
65  Create a 3x3 rotation matrix. Takes a direction as a single character
66  ('x', 'y', or 'z'), an angle (in rads) and outputs a rotation matrix
67 */
68 /************************************************************************/
69 /* Includes
70 */
71 #include <math.h>
72 #include "MathType.h"
73 
74 /************************************************************************/
75 /* Defines and macros
76 */
77 
78 /************************************************************************/
79 /* Globals
80 */
81 
82 /************************************************************************/
83 /* Prototypes
84 */
85 
86 /************************************************************************/
87 /*>void blCreateRotMat(char direction, REAL angle, REAL matrix[3][3])
88  ------------------------------------------------------------------
89 *//**
90 
91  \param[in] direction Axis about which to rotate
92  \param[in] angle Angle (in rads) to rotate
93  \param[out] matrix Rotation matrix
94 
95  Create a 3x3 rotation matrix. Takes a direction as a single character
96  ('x', 'y', or 'z'), an angle (in rads) and outputs a rotation matrix
97 
98 - 22.07.93 Original By: ACRM
99 - 07.07.14 Use bl prefix for functions By: CTP
100 */
101 void blCreateRotMat(char direction, REAL angle, REAL matrix[3][3])
102 {
103  int i, j,
104  m,
105  m1,
106  m2;
107  REAL CosTheta,
108  SinTheta;
109 
110  /* Initialise matrix to all 0.0 */
111  for(i=0; i<3; i++)
112  for(j=0; j<3; j++)
113  matrix[i][j] = 0.0;
114 
115  /* Select the items that need to be filled in */
116  switch(direction)
117  {
118  case 'x': case 'X':
119  m = 0;
120  break;
121  case 'y': case 'Y':
122  m = 1;
123  break;
124  case 'z': case 'Z':
125  m = 2;
126  break;
127  default: /* Just return the unit matrix */
128  for(i=0; i<3; i++)
129  matrix[i][i] = 1.0;
130  return;
131  }
132 
133  /* Find which items these relate to */
134  m1 = (m+1) % 3;
135  m2 = (m1+1) % 3;
136 
137  /* Fill in the values */
138  matrix[m][m] = 1.0;
139  CosTheta = (REAL)cos((double)angle);
140  SinTheta = (REAL)sin((double)angle);
141  matrix[m1][m1] = CosTheta;
142  matrix[m2][m2] = CosTheta;
143  matrix[m1][m2] = SinTheta;
144  matrix[m2][m1] = -SinTheta;
145 }
146 
147 
double REAL
Definition: MathType.h:67
void blCreateRotMat(char direction, REAL angle, REAL matrix[3][3])
Definition: CreateRotMat.c:101
Type definitions for maths.