From e860e146ccecf07d42aa53de885916931950245e Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Fri, 9 Oct 2015 16:17:49 +0200 Subject: [PATCH] Issue 4634: Simplify coord-rotate This does not fix the problem that (sin PI) is not really zero because of the MPU working with higher precision than PI is specified, but at least it makes the code nicer to read and modify. --- scm/lily-library.scm | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/scm/lily-library.scm b/scm/lily-library.scm index c5bf8cc59d..0bfce9eb0c 100644 --- a/scm/lily-library.scm +++ b/scm/lily-library.scm @@ -707,20 +707,13 @@ right (@var{dir}=+1)." (define-public (coord-scale coordinate amount) (coord-operation * amount coordinate)) -(define-public (coord-rotate coordinate degrees-in-radians) - (let* - ((coordinate - (cons - (exact->inexact (coord-x coordinate)) - (exact->inexact (coord-y coordinate)))) - (radius - (sqrt - (+ (* (coord-x coordinate) (coord-x coordinate)) - (* (coord-y coordinate) (coord-y coordinate))))) - (angle (angle-0-2pi (atan (coord-y coordinate) (coord-x coordinate))))) - (cons - (* radius (cos (+ angle degrees-in-radians))) - (* radius (sin (+ angle degrees-in-radians)))))) +(define-public (coord-rotate coordinate angle) + (let ((c (cos angle)) + (s (sin angle)) + (x (coord-x coordinate)) + (y (coord-y coordinate))) + (cons (- (* c x) (* s y)) + (+ (* s x) (* c y))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; trig -- 2.39.5