rot_3d added
This commit is contained in:
parent
d0086d6ae5
commit
deba331de9
24
README.md
24
README.md
@ -2,12 +2,28 @@
|
|||||||
|
|
||||||
A small teaching package for basic linear algebra operations.
|
A small teaching package for basic linear algebra operations.
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
**MatrixMania** is a lightweight educational package for performing basic linear algebra operations such as matrix multiplication, transposition, and generating 2D or 3D rotation matrices.
|
||||||
|
It is intended for learning and demonstration purposes.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Functions
|
## Functions
|
||||||
|
|
||||||
### `matmul(A, B)`
|
### `matmul(A, B)`
|
||||||
Matrix multiplication between two 2D lists.
|
Performs matrix multiplication between two 2D lists (matrices).
|
||||||
|
|
||||||
|
**Parameters**
|
||||||
|
- `A` (`List[List[float]]`): The first matrix.
|
||||||
|
- `B` (`List[List[float]]`): The second matrix.
|
||||||
|
|
||||||
|
**Returns**
|
||||||
|
- `List[List[float]]`: The resulting matrix product.
|
||||||
|
|
||||||
|
**Example**
|
||||||
```python
|
```python
|
||||||
>>> from matrixmania import matmul
|
from matrixmania import matmul
|
||||||
>>> matmul([[1, 2]], [[3], [4]])
|
|
||||||
[[11]]
|
print(matmul([[1, 2]], [[3], [4]]))
|
||||||
|
# [[11]]
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
from .compute import matmul, transpose, rot_2D
|
from .compute import matmul, transpose, rot_2D, rot_3D
|
||||||
@ -66,6 +66,59 @@ def rot_2D(theta: float) -> List[List[float]]:
|
|||||||
[sin_t, cos_t]
|
[sin_t, cos_t]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def rot_3D(angle: float, axis: str) -> List[List[float]]:
|
||||||
|
"""
|
||||||
|
Returns a 3D rotation matrix for a given angle and axis.
|
||||||
|
|
||||||
|
Rotates points in 3D space around the specified axis by the given angle.
|
||||||
|
The rotation follows the right-hand rule (counterclockwise when looking
|
||||||
|
along the axis of rotation).
|
||||||
|
|
||||||
|
Rotation matrices:
|
||||||
|
x-axis:
|
||||||
|
[[1, 0, 0],
|
||||||
|
[0, cosθ, -sinθ],
|
||||||
|
[0, sinθ, cosθ]]
|
||||||
|
|
||||||
|
y-axis:
|
||||||
|
[[ cosθ, 0, sinθ],
|
||||||
|
[ 0, 1, 0],
|
||||||
|
[-sinθ, 0, cosθ]]
|
||||||
|
|
||||||
|
z-axis:
|
||||||
|
[[cosθ, -sinθ, 0],
|
||||||
|
[sinθ, cosθ, 0],
|
||||||
|
[ 0, 0, 1]]
|
||||||
|
|
||||||
|
:param angle: Rotation angle in radians.
|
||||||
|
:param axis: Axis of rotation ('x', 'y', or 'z').
|
||||||
|
:return: A 3×3 rotation matrix as a list of lists.
|
||||||
|
:raises ValueError: If the axis is not 'x', 'y', or 'z'.
|
||||||
|
"""
|
||||||
|
cos_t = math.cos(angle)
|
||||||
|
sin_t = math.sin(angle)
|
||||||
|
|
||||||
|
if axis == 'x':
|
||||||
|
return [
|
||||||
|
[1, 0, 0],
|
||||||
|
[0, cos_t, -sin_t],
|
||||||
|
[0, sin_t, cos_t]
|
||||||
|
]
|
||||||
|
elif axis == 'y':
|
||||||
|
return [
|
||||||
|
[cos_t, 0, sin_t],
|
||||||
|
[0, 1, 0],
|
||||||
|
[-sin_t, 0, cos_t]
|
||||||
|
]
|
||||||
|
elif axis == 'z':
|
||||||
|
return [
|
||||||
|
[cos_t, -sin_t, 0],
|
||||||
|
[sin_t, cos_t, 0],
|
||||||
|
[0, 0, 1]
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
raise ValueError("Axis must be 'x', 'y', or 'z'.")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# Test matrix multiplication
|
# Test matrix multiplication
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "matrixmania_shehibr"
|
name = "matrixmania_shehibr"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
description = "MatrixMania: Simple linear algebra functions for teaching (matmul, transpose,rot_2D)."
|
description = "MatrixMania: Simple linear algebra functions for teaching (matmul, transpose,rot_2D)."
|
||||||
authors = [
|
authors = [
|
||||||
{ name="shehibr", email="shehibr98345@th-nuernberg.de" }
|
{ name="shehibr", email="shehibr98345@th-nuernberg.de" }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user