2D Rotation around a point
# Rotate a point (x, y) around a center (cx, cy) by angle θ (in radians)
function rotate_point(x, y, cx, cy, θ):
# Step 1: Translate point so center is at origin
tx = x - cx
ty = y - cy
# Step 2: Apply rotation
rx = tx * cos(θ) - ty * sin(θ)
ry = tx * sin(θ) + ty * cos(θ)
# Step 3: Translate back
new_x = rx + cx
new_y = ry + cy
return (new_x, new_y)
Notes: - Use radians for θ (θ = degrees × π / 180 if needed). - Positive θ rotates counterclockwise.