[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Simplify coord-rotate (issue 263690043 by address@hidden)

**From**: |
thomasmorley65 |

**Subject**: |
Simplify coord-rotate (issue 263690043 by address@hidden) |

**Date**: |
Sat, 10 Oct 2015 20:08:28 +0000 |

Great simplification!
Though, I'd like to add two features
1)
Making it possible to rotate at a different point other than (0 . 0)
2)
Getting the needed exactness as discussed starting:
http://lists.gnu.org/archive/html/lilypond-user/2015-10/msg00320.html
Below my attempt following your advice. I tried make it as concise as
possible, but ofcourse it is now far more complex again.
(define (get-PI/4-rotated-quadrants radians)
(cond ((>= radians TWO-PI)
(get-PI/4-rotated-quadrants (- radians TWO-PI)))
((< radians 0)
(get-PI/4-rotated-quadrants (+ radians TWO-PI )))
(else
(let* (;; get the octants
(oct (truncate (/ radians (/ PI 4)))))
;; get the rotated quadrants
(if (even? oct)
(/ oct 2)
(/ (1+ oct) 2))))))
(define*-public
(coord-rotate coordinate angle-in-radians #:optional (middle '(0 .
0)))
(let* ((angle (angle-0-2pi angle-in-radians))
(quadrant (get-PI/4-rotated-quadrants angle-in-radians))
(moved-angle (- angle (/ (* quadrant PI) 2)))
(x (coord-x coordinate))
(y (coord-y coordinate))
(c (cos moved-angle))
(s (sin moved-angle))
(xs (* x s))
(xc (* x c))
(ys (* y s))
(yc (* y c))
(rotated-round-zero
(cond ((= quadrant 1)
(cons
(- (- xs) (- yc))
(- (+ (- xc) (- ys)))))
((= quadrant 2)
(cons
(- (- xc) (- ys))
(+ (- xs) (- yc))))
((= quadrant 3)
(cons
(- xs yc)
(- (+ xc ys))))
(else
(cons
(- xc ys)
(+ xs yc))))))
(cons
(+ (coord-x middle) (coord-x rotated-round-zero))
(+ (coord-y middle) (coord-y rotated-round-zero)))))
https://codereview.appspot.com/263690043/

**Simplify coord-rotate (issue 263690043 by address@hidden)**,
*thomasmorley65* **<=**