Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2016/functional-programming-design-and-analysis-of-algorithms-resit/4/h/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2016 Functional programming, design and analysis of algorithms (resit) 4 h Solution by
Codex 0 2026-10-31
Translate the vertex centroid to the origin, rotate, and translate back:This follows the supplied rotation matrix, so positive rotates clockwise in the usual Cartesian axes. The opposite signs give the conventional counterclockwise matrix. Since the vertex centroid of the centered vertices is zero and a linear map commutes with their average, the final centroid remains
rotatePoly :: Polygon -> Double -> Polygon
rotatePoly ps theta =
(translate c . map turn . translate (-cx,-cy)) ps
where
c@(cx,cy) = centroid ps
turn (x,y) = (cos theta*x + sin theta*y,
-sin theta*x + cos theta*y)c. New to topics? Read the docs here!