File: mat.rst

package info (click to toggle)
openstructure 2.9.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 205,228 kB
  • sloc: cpp: 188,129; python: 35,361; ansic: 34,298; fortran: 3,275; sh: 286; xml: 146; makefile: 29
file content (167 lines) | stat: -rw-r--r-- 5,108 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
Matrices
================================================================================

.. currentmodule:: ost.geom

The :mod:`~ost.geom` module defines matrices in two, three and four dimensions. 
All matrices store the values in row-major order, meaning that, the matrix ((1, 
2), (3,4)) stores the values as (1, 2, 3, 4). This is illustrated in 
the following code examples:

.. code-block:: python

  m=geom.Mat2(1, 2, 3, 4)
  print(m) # will print {{1,2},{3,4}}
  print(m[(0,0)], m[(0,1)], m[(1,0)], m[(1,1)]) # will print 1, 2, 3, 4

Matrices support arithmetic via overloaded operators. The following operations are 
supported:

  * adding and subtracting two matrices
  * negation
  * multiplication of matrices
  * multiplying and dividing by scalar value

The Matrix Classes
--------------------------------------------------------------------------------

.. class:: Mat2()
           Mat2(d00, d01, d10, d11)

  2x2 real-valued matrix. The first signature creates a new identity matrix. The 
  second signature initializes the matrix in row-major order. 

  .. staticmethod:: Identity()
  
    Returns the 2x2 identity matrix
  
  
.. class:: Mat3()
           Mat3(d00, d01, d02, d10, d11, d12, d20, d21, d22)

  3x3 real-valued matrix. The first signature creates a new identity matrix. The 
  second signature initializes the matrix in row-major order.
  
  .. staticmethod:: Identity()
  
    Returns the 3x3 identity matrix
    
.. class:: Mat4()
           Mat4(d00, d01, d02, d03, d10, d11, d12, d13, d20, d21, d22, d23, d30, d31, d32, d33)

  4x4 real-valued matrix. The first signature creates a new identity matrix. The 
  second signature initializes the matrix in row-major order.
  
  .. method:: ExtractRotation()
    
    Returns the 3x3 submatrix
    
  .. method:: PasteRotation(mat)
  
    Set the 3x3 submatrix of the top-left corner to `mat`
    
  .. method:: ExtractTranslation()
  
    Extract translation component from matrix. Only meaningful when matrix 
    is a combination of rotation and translation matrices, otherwise the result 
    is undefined.
    
  .. PasteTranslation(trans)
  
    Set the translation component of the matrix to `trans`
    
    :param trans: The translation
    :type  trans: :class:`Vec3`
    
  .. staticmethod:: Identity()
  
    Returns the 4x4 identity matrix

Functions Operating on Matrices
--------------------------------------------------------------------------------
.. function:: Equal(lhs, rhs, epsilon=geom.EPSILON)

  Compares the two matrices `lhs` and `rhs` and returns True, if all 
  of the element-wise differences are smaller than epsilon. `lhs` 
  and `rhs` must be matrices of the same dimension.
  
  :param lhs: First matrix
  :type  lhs: :class:`Mat2`, :class:`Mat3` or :class:`Mat4`
  :param rhs: Second matrix
  :type  rhs: :class:`Mat2`, :class:`Mat3` or :class:`Mat4`

.. function:: Transpose(mat)

  Returns the transpose of `mat`
  
  :param mat: The matrix to be transposed
  :type  lhs: :class:`Mat2`, :class:`Mat3` or :class:`Mat4`

.. function:: Invert(mat)

  Returns the inverse of `mat`
  
  :param mat: The matrix to be inverted
  :type  mat: :class:`Mat2`, :class:`Mat3` or :class:`Mat4`
  
  What happens when determinant is 0?
  
.. function:: CompMultiply(lhs, rhs)

  Returns the component-wise product of `lhs` and `rhs`. `lhs` and 
  `rhs` must be vectors of the same dimension.
  
  :param lhs: The lefthand-side vector
  :type  lhs: :class:`~Vec2`, :class:`~Vec3` or 
              :class:`~Vec4`
  :param rhs: The righthand-side vector
  :type  rhs: :class:`~Vec2`, :class:`~Vec3` or 
              :class:`~Vec4`
              
.. function:: CompDivide(lhs, rhs)

  Returns the component-wise quotient of `lhs` divided by `rhs`. `lhs` 
  and `rhs` must be vectors of the same dimension.

  :param lhs: The lefthand-side vector
  :type  lhs: :class:`~Vec2`, :class:`~Vec3` or 
              :class:`~Vec4`
  :param rhs: The righthand-side vector
  :type  rhs: :class:`~Vec2`, :class:`~Vec3` or 
              :class:`~Vec4`

.. function:: Det(mat)

  Returns the determinant of `mat`
  :param mat: A matrix
  :type  mat: :class:`~Mat2`, :class:`~Mat3` or :class:`~Mat4`

.. function:: Minor(mat, i, j)
  
  Returns the determinant of the 2x2 matrix generated from `mat`  by 
  removing the ith row and jth column.

.. function:: EulerTransformation(phi, theta, xi)
  
  Returns a rotation matrix for the 3 euler angles `phi`, `theta`, and
  `xi`. The 3 angles are given in radians.
  
  
.. function:: AxisRotation(axis, angle)

  Returns a rotation matrix that represents a rotation of `angle` 
  around the `axis`. 
  
  :param axis: The rotation axis. Will be normalized
  :type  axis: :class:`Vec3`
  :param angle: Rotation angle (radians) in clockwise direction when 
      looking down the axis.
  
.. function:: OrthogonalVector(vec)

  Get arbitrary vector orthogonal to `vec`. The returned vector is of length 
  1, except when `vec` is a zero vector. In that case, the returned vector is 
  (0, 0, 0).
  
  :param vec: A vector of arbitrary length
  :type vec: :class:`Vec3`