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

**From**: |
thomasmorley65 |

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

**Date**: |
Thu, 15 Oct 2015 12:34:17 +0000 |

Please disregard my code from comment #1, it's fishy.
More appropiate would be (dropping the idea to rotate around other ponts
than zero):
#(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
(cond ((= oct 7) 0)
((even? oct)
(/ oct 2))
(else (/ (1+ oct) 2)))))))
(define-public (coord-rotate-p-II 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* ((angle (angle-0-2pi angle-in-radians))
(quadrant (get-PI/4-rotated-quadrants angle))
(moved-angle (- angle (/ (* quadrant PI) 2)))
(cm (cos moved-angle))
(sm (sin moved-angle))
(c (cond ((= 1 quadrant) (- sm))
((= 2 quadrant) (- cm))
((= 3 quadrant) sm)
(else cm)))
(s (cond ((= 1 quadrant) cm)
((= 2 quadrant) (- sm))
((= 3 quadrant) (- cm))
(else sm)))
(x (coord-x coordinate))
(y (coord-y coordinate)))
(cons (- (* c x) (* s y))
(+ (* s x) (* c y)))))
Maybe in a follow up?
The patch itself LGTM
https://codereview.appspot.com/263690043/