## #168 logarc of atan2 wrong

closed
nobody
5
2006-11-09
2002-10-22
No

res : logarc(atan2(y,x))\$
rectform(res),y=1,x=-1;
=&gt; -%pi/4

BUT

atan2(1,-1) =&gt; 3*%pi/4

The fix is to change the formula in \$logarc and in
simpatan2. Currently, logarc(atan2(y,x)) =&gt; logarc(atan
(y/x)), which gives incorrect results as above.

This formula should be replaced by

-%i*log((y+%i*x)/sqrt(x^2+y^2))

## Discussion

• Robert Dodier - 2006-07-01
• labels: --> 460522

• Robert Dodier - 2006-09-09
• labels: 460522 --> Lisp Core - Trigonometry

• Raymond Toy - 2006-11-09

Logged In: YES
user_id=28849

Isn't this formula also wrong? For y=1, x=-1, the formula
becomes -%i*log((1-%i)/sqrt(2)). But log is the principal
log so we still get -%pi/4.

I think it would be better to make atan2 be in the range
(-%pi,%pi].

• Raymond Toy - 2006-11-09

Logged In: YES
user_id=28849

Oops. I think the formula was intended to be
-%i*log((x+%i*y)/sqrt(x^2+y^2)).

That produces the correct values. At least
factor(rectform(<formula>)) produces atan2(y/r,x/r) with r =
sqrt(x^2+y^2).

It would be nice if atan2 simplified out the denominator to
leave only atan2(y,x).

• Raymond Toy - 2006-11-09
• status: open --> closed

• Raymond Toy - 2006-11-09

Logged In: YES
user_id=28849

Fixed as suggested, with slight correction.