rot_2D hat jetzt Winkel im Bogenmaß
This commit is contained in:
1 parent
0fc2076efc
commit
18ca855c76
1 file changed
+6
-4
+6
-4
@@ -92,7 +92,7 @@ def transpose(matrix: Matrix) -> Matrix:
|
|||||||
|
|
||||||
|
|
||||||
def rot_2D(theta: float) -> list[list[float]]:
|
def rot_2D(theta: float) -> list[list[float]]:
|
||||||
"""Return the 2‑D rotation matrix for angle *theta* in degrees.
|
"""Return the 2‑D rotation matrix for angle *theta* in radians.
|
||||||
|
|
||||||
The matrix is
|
The matrix is
|
||||||
``[[cos(θ), -sin(θ)],
|
``[[cos(θ), -sin(θ)],
|
||||||
@@ -102,7 +102,7 @@ def rot_2D(theta: float) -> list[list[float]]:
|
|||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
theta : float
|
theta : float
|
||||||
Rotation angle in degrees (clockwise).
|
Rotation angle in radians (clockwise).
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
@@ -110,7 +110,8 @@ def rot_2D(theta: float) -> list[list[float]]:
|
|||||||
2x2 rotation matrix.
|
2x2 rotation matrix.
|
||||||
"""
|
"""
|
||||||
import math
|
import math
|
||||||
rad = math.radians(theta)
|
# Treat theta as radians directly
|
||||||
|
rad = theta
|
||||||
cos_t = math.cos(rad)
|
cos_t = math.cos(rad)
|
||||||
sin_t = math.sin(rad)
|
sin_t = math.sin(rad)
|
||||||
return [[cos_t, -sin_t], [sin_t, cos_t]]
|
return [[cos_t, -sin_t], [sin_t, cos_t]]
|
||||||
@@ -141,7 +142,8 @@ def rotate(matrix: Matrix, degrees: float) -> Matrix:
|
|||||||
return []
|
return []
|
||||||
n_rows, n_cols = len(matrix), len(matrix[0])
|
n_rows, n_cols = len(matrix), len(matrix[0])
|
||||||
# rotation matrix
|
# rotation matrix
|
||||||
r = rot_2D(degrees)
|
import math
|
||||||
|
r = rot_2D(math.radians(degrees))
|
||||||
cos_t, sin_t = r[0][0], r[1][0] # cos and sin from 2x2 matrix
|
cos_t, sin_t = r[0][0], r[1][0] # cos and sin from 2x2 matrix
|
||||||
# centre of the matrix (half‑index)
|
# centre of the matrix (half‑index)
|
||||||
c_row = (n_rows - 1) / 2.0
|
c_row = (n_rows - 1) / 2.0
|
||||||
|
|||||||
Reference in new issue
Block a user