118 lines
1.8 KiB
Markdown
118 lines
1.8 KiB
Markdown
# MatrixMania
|
|
|
|
This Package contains a few fundamental function which can be used for **matrices**.
|
|
|
|
## Functions:
|
|
|
|
- matmul function
|
|
- transpose function
|
|
- rot_2D function
|
|
- rot_3D function
|
|
- project_ortho
|
|
|
|
## matmul function:
|
|
|
|
This function calculates the matrix multiplication with 2 matrices.
|
|
It also checks if the matrices are compatible for multiplication.
|
|
|
|
**Example:**
|
|
|
|
```
|
|
matrix_a = [[3, 4, -1, 4],
|
|
[-2, 2, 5, 1]]
|
|
|
|
matrix_b = [[1, 3, -2],
|
|
[2, 5, 1],
|
|
[-1, 4, -4],
|
|
[2, 3, 6]]
|
|
|
|
matrix_c = matmul(matrix_a, matrix_b)
|
|
print("matrix c:")
|
|
print(tabulate(matrix_c))
|
|
```
|
|
|
|
**Result:**
|
|
|
|
```
|
|
matrix c:
|
|
-- -- --
|
|
20 37 26
|
|
-1 27 -8
|
|
-- -- --
|
|
```
|
|
|
|
|
|
## transpose function:
|
|
|
|
This function transposes a matrix.
|
|
|
|
**Example:**
|
|
|
|
```
|
|
matrix = [[1, 2, 3],
|
|
[4, 5, 6]]
|
|
|
|
new_matrix = transpose(matrix)
|
|
print("transposed matrix:")
|
|
print(tabulate(new_matrix))
|
|
```
|
|
|
|
**Result:**
|
|
|
|
```
|
|
transposed matrix:
|
|
- -
|
|
1 4
|
|
2 5
|
|
3 6
|
|
- -
|
|
|
|
```
|
|
|
|
## rot_2D function:
|
|
|
|
This function returns the rotation matrix for a given angle.
|
|
|
|
**Example:**
|
|
|
|
```
|
|
theta = math.pi / 2
|
|
R = rot_2D(theta)
|
|
|
|
print("rotation matrix for 90°:")
|
|
print(tabulate(R))
|
|
```
|
|
|
|
**Result**
|
|
|
|
```
|
|
rotation matrix for 90°:
|
|
----------- ------------
|
|
6.12323e-17 -1
|
|
1 6.12323e-17
|
|
----------- ------------
|
|
```
|
|
|
|
## rot_3D function:
|
|
This function calculates the rotation matrix for one 3D axis (x, y, z) for a certain angle.
|
|
|
|
**Example:**
|
|
```
|
|
theta = math.pi / 2
|
|
R = rot_3D(theta, "y")
|
|
|
|
print("rotation matrix for 90° on the y axis:")
|
|
print(tabulate(R))
|
|
```
|
|
**Result:**
|
|
```
|
|
rotation matrix for 90° on the y axis:
|
|
------------ - -----------
|
|
6.12323e-17 0 1
|
|
0 1 0
|
|
-1 0 6.12323e-17
|
|
------------ - -----------
|
|
```
|
|
|
|
## project_ortho function:
|
|
This functions projects a 3D point on a 2D display |