Hausaufgabe tests hinzufügen und §D funktion in commit
This commit is contained in:
1 parent
153b0ac6b4
commit
bf436441ce
4 files changed
+90
No files matched your search
@@ -2,6 +2,7 @@
|
||||
name = "matrixmania"
|
||||
version = "0.1.0"
|
||||
dependencies = ["tabulate", "ruff"]
|
||||
|
||||
[project.optional-dependencies]
|
||||
dev = ["pytest", "ruff", "pytest-cov"]
|
||||
|
||||
|
||||
@@ -104,6 +104,65 @@ def rot_2D(winkel):
|
||||
]
|
||||
|
||||
def rot_3D(angle: float, axis: str) -> list[list[float]]:
|
||||
"""Gibt die Rotationsmatrix für einen Winkel in Radiant um die x-, y- oder z-Achse zurück.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
angle : float
|
||||
Rotationswinkel in Radiant.
|
||||
axis : str
|
||||
Rotationsachse: ``"x"``, ``"y"`` oder ``"z"``.
|
||||
|
||||
Returns
|
||||
-------
|
||||
list[list[float]]
|
||||
Die entsprechende 3x3-Rotationsmatrix.
|
||||
|
||||
Raises
|
||||
------
|
||||
ValueError
|
||||
Wenn ``axis`` nicht ``"x"``, ``"y"`` oder ``"z"`` ist.
|
||||
|
||||
Formeln
|
||||
-------
|
||||
Rx(theta) =
|
||||
[[1, 0, 0],
|
||||
[0, cos(theta), -sin(theta)],
|
||||
[0, sin(theta), cos(theta)]]
|
||||
|
||||
Ry(theta) =
|
||||
[[cos(theta), 0, sin(theta)],
|
||||
[0, 1, 0],
|
||||
[-sin(theta), 0, cos(theta)]]
|
||||
|
||||
Rz(theta) =
|
||||
[[cos(theta), -sin(theta), 0],
|
||||
[sin(theta), cos(theta), 0],
|
||||
[0, 0, 1]]
|
||||
"""
|
||||
if axis == "x":
|
||||
return [
|
||||
[1.0, 0.0, 0.0],
|
||||
[0.0, math.cos(angle), -math.sin(angle)],
|
||||
[0.0, math.sin(angle), math.cos(angle)],
|
||||
]
|
||||
|
||||
if axis == "y":
|
||||
return [
|
||||
[math.cos(angle), 0.0, math.sin(angle)],
|
||||
[0.0, 1.0, 0.0],
|
||||
[-math.sin(angle), 0.0, math.cos(angle)],
|
||||
]
|
||||
|
||||
if axis == "z":
|
||||
return [
|
||||
[math.cos(angle), -math.sin(angle), 0.0],
|
||||
[math.sin(angle), math.cos(angle), 0.0],
|
||||
[0.0, 0.0, 1.0],
|
||||
]
|
||||
|
||||
raise ValueError("axis must be 'x', 'y' or 'z'")
|
||||
|
||||
def transpose(a: list[list[float]]) -> list[list[float]]:
|
||||
"""Gibt die transponierte Matrix a zurück."""
|
||||
return [
|
||||
|
||||
Whitespace-only changes.
@@ -0,0 +1,30 @@
|
||||
import math
|
||||
import pytest
|
||||
|
||||
from matrixmania.compute import rot_2D, rot_3D
|
||||
|
||||
def test_rot2D_90_grad(): # dreht es sich wirklich um 90 grad?
|
||||
#Arrange
|
||||
angle = math.pi/2
|
||||
expected = [
|
||||
[math.cos(angle), -math.sin(angle)],
|
||||
[math.sin(angle), math.cos(angle)]
|
||||
]
|
||||
|
||||
#Act
|
||||
result = rot_2D(angle)
|
||||
#Assert
|
||||
assert result == expected
|
||||
|
||||
def test_rot3D_drehen(): #dreht sich um 90 grad?
|
||||
#Arrange
|
||||
angle = math.pi/2
|
||||
achse = "z"
|
||||
expected = [
|
||||
[math.cos(angle), -math.sin(angle), 0.0],
|
||||
[math.sin(angle), math.cos(angle), 0.0],
|
||||
[0.0, 0.0, 1.0],
|
||||
]
|
||||
|
||||
result = rot_3D(angle, achse)
|
||||
assert result == expected
|
||||
Reference in new issue
Block a user