# Tactiverge Academy — companion code for "Rotations in 2D"
# Lesson: https://tactiverge.win/academy/robotics-foundations/mathematical-foundations-of-movement/rotations-in-2d/
# Licence: MIT (see https://tactiverge.win/open-engineering/). Examples appear in lesson order.

# ── Example 1 ────────────────────────────────────────
import math

def rotate(point, degrees):
    """Rotate a 2D point anticlockwise about the origin."""
    t = math.radians(degrees)
    x, y = point
    return (x * math.cos(t) - y * math.sin(t),
            x * math.sin(t) + y * math.cos(t))

p = (2, 1)
for angle in [90, 30, -30, 360]:
    x, y = rotate(p, angle)
    print(f"{angle:4d} deg: ({x:6.3f}, {y:6.3f})  length {math.hypot(x, y):.3f}")
