From 75aa9281227dafb4b2c6e2f39b3fe5ed532e7007 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Tue, 30 Aug 2016 19:40:06 +0200 Subject: Issue 4968/1: Add coord-rotated function Uses it for implementing coord-rotate. --- scm/lily-library.scm | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/scm/lily-library.scm b/scm/lily-library.scm index bbbe3cc53a..214c095cf2 100644 --- a/scm/lily-library.scm +++ b/scm/lily-library.scm @@ -708,29 +708,15 @@ right (@var{dir}=+1)." (coord-operation * amount coordinate)) (define-public (coord-rotate coordinate angle-in-radians) - ;; getting around (sin PI) not being exactly zero by switching to cos at - ;; appropiate angles and/or taking the negative value (vice versa for cos) - (let* ((quadrant (inexact->exact (round (/ angle-in-radians (/ PI 2))))) - (moved-angle (- angle-in-radians (* quadrant (/ PI 2)))) - (s (sin moved-angle)) - (c (cos moved-angle)) - (x (coord-x coordinate)) - (y (coord-y coordinate))) - (case (modulo quadrant 4) - ((0) ;; -45 .. 45 - (cons (- (* c x) (* s y)) - (+ (* s x) (* c y)))) - ((1) ;; 45 .. 135 - (cons (- (* (- s) x) (* c y)) - (+ (* c x) (* (- s) y)))) - ((2) ;; 135 .. 225 - (cons (- (* (- c) x) (* (- s) y)) - (+ (* (- s) x) (* (- c) y)))) - ((3) ;; 225 .. 315 - (cons (- (* s x) (* (- c) y)) - (+ (* (- c) x) (* s y)))) - ;; for other angles (modulo quadrant 4) returns one of the above cases - ))) + (coord-rotated coordinate (/ angle-in-radians PI-OVER-180))) + +(define-public (coord-rotated coordinate direction) + ;; Same, in degrees or with a given direction + (let ((dir (ly:directed direction))) + (cons (- (* (car dir) (car coordinate)) + (* (cdr dir) (cdr coordinate))) + (+ (* (car dir) (cdr coordinate)) + (* (cdr dir) (car coordinate)))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; trig -- cgit v1.2.3