[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: modulo 2 pi?
From: |
Johan Kullstam |
Subject: |
Re: modulo 2 pi? |
Date: |
Tue, 27 Jan 2009 23:25:28 -0500 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) |
Søren Hauberg <address@hidden> writes:
> ons, 21 01 2009 kl. 14:23 +0100, skrev Francesco Potortì:
>> >If I have two angles 'theta' and 'psi', and I want to compute their
>> >difference I can simply do
>> >
>> > d = theta - psi;
>> >
>> >However, I'd like this result to be in the range [0, 2*pi]. Can I simply
>> >do
>> >
>> > d = mod (theta - psi, 2*pi);
>> >
>> >or will this fail in some cases?
>>
>> It should not. It would fail if you used 'rem', but using 'mod' you
>> should have no problems.
>
> Thanks. I've been using 'mod' for some time now, but I wanted to double
> check.
You can also use cos, sin and atan2 as in atan2(sin(theta),cos(theta)).
Sometimes it is more convenient to use the complex number
z = exp(I*theta)
instead of the real number theta.
Use multiplication of z instead of addition (and division for
subtraction). The angle wraps naturally. Welcome to the Lie group
U(1,C).
For your case:
t = exp(I*theta);
p = exp(I*psi);
d = t/p;
delta = arg(d);
delta will be between -pi and +pi.
Looking at the help information
~:> help arg
-- Mapping Function: arg (Z)
-- Mapping Function: angle (Z)
Compute the argument of Z, defined as THETA = `atan (Y/X)'. in
radians.
The above is wrong as it should be atan2(Y,X) not atan(Y/X). How to
file a bug against the documentation?
--
Johan KULLSTAM