A rotation matrix turns every point around the origin by the same angle.
What to build
Rotate a point counterclockwise about the origin by an angle in degrees.
Requirements
- Read the angle and the point.
- Apply the rotation matrix [[cos θ, −sin θ], [sin θ, cos θ]].
- Print the new coordinates with 4 decimal places.
Input
Line 1: the angle in degrees (a decimal). Line 2: x and y (decimals).
Output
One line: X Y, each to 4 decimal places.
Constraints
The angle is between -360 and 360 and the coordinates between -100 and 100.
Example
Input:
90
1 0
Output:
0.0000 1.0000
Why it works
The columns of the rotation matrix are where (1, 0) and (0, 1) go: (cos θ, sin θ) and (−sin θ, cos θ). Every point is a mix of those two, so the formulas follow. Rotation keeps lengths unchanged.
Examples
90 1 0
0.0000 1.0000
45 1 1
0.0000 1.4142
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
Use x' = x cos θ − y sin θ and y' = x sin θ + y cos θ.
Hint 2
Convert the angle with `radians` from the `math` module.
Hint 3
Print with `round(v, 4) + 0.0` first so you never print -0.0000.
Solution
Show one correct solution (try it yourself first)
from math import cos, sin, radians
deg = float(input())
x, y = [float(v) for v in input().split()]
t = radians(deg)
nx = x * cos(t) - y * sin(t)
ny = x * sin(t) + y * cos(t)
print(f"{round(nx, 4) + 0.0:.4f} {round(ny, 4) + 0.0:.4f}")
▶ Open this solution in the compiler, then press Visualize to watch it run step by step