Added Rot3D
This commit is contained in:
+27
-2
@@ -74,7 +74,32 @@ def rot_2D(angle: int) -> List[List[float]]:
|
||||
|
||||
return [[zahl1, zahl2], [zahl3, zahl4]]
|
||||
|
||||
def rot_3D(angle: float, axis: str) -> List[List[float]]:
|
||||
"""
|
||||
Rotation matrix 3D
|
||||
:param angle: between 0 and 360 degrees
|
||||
:param axis: x,y,z axis of rotation matrix
|
||||
:return: 3D rotation matrix
|
||||
"""
|
||||
if angle > 360:
|
||||
raise ValueError("angle must be less than 360")
|
||||
elif angle < 0:
|
||||
raise ValueError("angle must be greater than 0")
|
||||
|
||||
cos = math.cos(math.radians(angle))
|
||||
sin = math.sin(math.radians(angle))
|
||||
|
||||
if axis == "x":
|
||||
return [[1,0,0],[0, cos, -sin],[0, sin, cos]]
|
||||
elif axis == "y":
|
||||
return [[cos, 0, sin],[0,1,0],[-sin,0,cos]]
|
||||
elif axis == "z":
|
||||
return [[cos, -sin, 0],[sin, cos, 0],[0, 0, 1]]
|
||||
|
||||
else:
|
||||
raise ValueError("Not a valid axis. Choose from 'x', 'y', 'z'.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
"alles selbst gemacht"
|
||||
print(rot_2D())
|
||||
|
||||
print(rot_3D(90, "x"))
|
||||
Reference in New Issue
Block a user