rot_3D mit Tests für rot_2D und rot_3D
This commit is contained in:
1 parent
d633de0293
commit
bc2c069bda
2 files changed
+96
No files matched your search
+31
@@ -116,6 +116,37 @@ def project_perspective(
|
||||
return (x * focal_length / depth * scale, y * focal_length / depth * scale)
|
||||
|
||||
|
||||
def rot_3D(angle: float, axis: str) -> list[list[float]]:
|
||||
"""Gibt die 3D-Rotationsmatrix für eine Drehung um eine Koordinatenachse zurück.
|
||||
|
||||
Rotation um die x-Achse:
|
||||
[[1, 0, 0], [0, cos(a), -sin(a)], [0, sin(a), cos(a)]]
|
||||
Rotation um die y-Achse:
|
||||
[[cos(a), 0, sin(a)], [0, 1, 0], [-sin(a), 0, cos(a)]]
|
||||
Rotation um die z-Achse:
|
||||
[[cos(a), -sin(a), 0], [sin(a), cos(a), 0], [0, 0, 1]]
|
||||
|
||||
Args:
|
||||
angle: Drehwinkel a im Bogenmaß.
|
||||
axis: Drehachse, "x", "y" oder "z".
|
||||
|
||||
Returns:
|
||||
Die 3x3-Rotationsmatrix als verschachtelte Liste.
|
||||
|
||||
Raises:
|
||||
ValueError: Wenn axis nicht "x", "y" oder "z" ist.
|
||||
"""
|
||||
cos_a = math.cos(angle)
|
||||
sin_a = math.sin(angle)
|
||||
if axis == "x":
|
||||
return [[1, 0, 0], [0, cos_a, -sin_a], [0, sin_a, cos_a]]
|
||||
if axis == "y":
|
||||
return [[cos_a, 0, sin_a], [0, 1, 0], [-sin_a, 0, cos_a]]
|
||||
if axis == "z":
|
||||
return [[cos_a, -sin_a, 0], [sin_a, cos_a, 0], [0, 0, 1]]
|
||||
raise ValueError("axis muss 'x', 'y' oder 'z' sein")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
matrix_a = [
|
||||
[3, 4, -1, 4],
|
||||
|
||||
Reference in new issue
Block a user