lilypond-devel
[Top][All Lists]

## Re: [PATCH] Re: not-so-ancient flags

 From: Carl D. Sorensen Subject: Re: [PATCH] Re: not-so-ancient flags Date: Sat, 13 Dec 2008 11:06:01 -0700

```

On 12/13/08 8:04 AM, "Han-Wen Nienhuys" <address@hidden> wrote:

> On Sat, Dec 13, 2008 at 11:48 AM, Reinhold Kainhofer
>
>> - -) What's the best way to convert an angle/length pair of polar coordinates
>>    (angle given in degree) to cartesian coordinates in scheme / guile? I
>>    don't want it as a complex number, but as a pair of reals...
>
> Well, both are equivalent, so I think using complex numbers is
> actually the quickest.
>

But complex numbers need angles in radians, not degrees, so you at least
need to do some conversion.

Here's a new version that uses complex numbers.

(define (polar->rectangular polar-pair)
"Convert @code{polar-pair}, a pair containing (magnitude .
angle-in-degrees)
to (x-length . y-length)"
(let* ((conversion-constant (/ (atan 1 1) 45))
(complex (make-polar
(car polar-pair)
(* conversion-constant (cdr polar-pair)))))
(cons
(real-part complex)
(imag-part complex))))

Carl

```