Message Boards Message Boards

1
|
5607 Views
|
13 Replies
|
1 Total Likes
View groups...
Share
Share this post:

PlanarAngle issues?

Posted 2 years ago

I am observing a very strange behavior from PlanarAngle:

  1. The result of PlanarAngle depends on the previous history.
  2. PlanerAngle assumes for the first few calls that its arguments are complex. After that, it doesn't.

Fortunately, however, all results are correct.

Attachments:
POSTED BY: Werner Geiger
13 Replies
Posted 2 years ago

I am also using Windows 10 and Mathematica 12.3.1. And I can not reproduce the issue. No matter how many times PlanarAngle[{0,1} -> {{-Sin ... is evaluated the output always contains Conjugate

Table[PlanarAngle[{0, 1} -> {{-Sin[\[Phi]], Cos[\[Phi]]}, {Cos[\[Phi]], Sin[\[Phi]]}}], 50]
POSTED BY: Hans Milton
Posted 2 years ago

Hmm, this is another miracle.

For me, your code executed in a freshly loaded kernel looks like: enter image description here

POSTED BY: Werner Geiger
Posted 2 years ago

Werner, so far I had only tried the code on Mathematica installed on my computer. The so called Mathematica|Desktop. And there are no problems.

But after your recent reply I tried it on the Wolfram Cloud. And I get exactly the same strange results that you have described!

POSTED BY: Hans Milton
Posted 2 years ago

After testing a bit more on another W10 computer I must correct myself. There the change from complex to real also appears, but later than it does on the Cloud. Typically around the 14th evaluation.

Table[{i, PlanarAngle[{0, 1} -> {{-Sin[\[Phi]], Cos[\[Phi]]}, {Cos[\[Phi]], Sin[\[Phi]]}}]}, {i, 50}]
POSTED BY: Hans Milton
Posted 2 years ago

I did not try that within the cloud but on the desktop only. I use a Wolfram|One license.

POSTED BY: Werner Geiger
Posted 2 years ago

Very very strange. Does anybody have any idea what happens here?

I think repeatability and reproducibility shoul be one of the most basic features of programming languages. PlanarAngle seems to show a kind of randomness instead.

POSTED BY: Werner Geiger

This is clearly a bug and should be reported here. To work around the issue until it is fixed, I recommend calling ClearSystemCache[] before PlanarAngle.

POSTED BY: Jason Biggs
Posted 2 years ago

@Jason: This makes results at least reproducible, just like Remove, ClearAll do (see above). But it is a very expensive operation since it clears all cached intermediate results so far.

We now have: enter image description here

Of course it doesn't prevent PlanarAngle from changing its behavior.

I reported this as a bug to Wolfram Support.

POSTED BY: Werner Geiger
Posted 2 years ago

A somewhat rough workaround could be to use VectorAngle instead:

myPlanarAngle[p_, q1_, q2_] := VectorAngle[q1 - p, q2 - p]

Table[{i, myPlanarAngle[{0, 1}, {-Sin[\[Phi]], Cos[\[Phi]]}, {Cos[\[Phi]], Sin[\[Phi]]}]}, {i, 50}]
POSTED BY: Hans Milton
Posted 2 years ago

@Hans: Yes, VectorAngle[u,v] remains stable. But VectorAngle is very different from PlanarAngle since it does not honor the direction of rotation. It gives the smaller of the two angles between u and v. Hence it is useless for calculating rotation angles. You must enhance it with quite complicated case diffentiations according to the relative positions of p, q1, q2. This is why PlanarAngle exists. See:

p = {0, 0}; q1 = {1, 0};
Print[{q2 = #, VectorAngle[q1 - p, q2 - p], 
     PlanarAngle[p -> {q1, q2}, "Counterclockwise"]}] & /@ {{-1, 
    1}, {-1, -1}};

{{-1,1},(3 \[Pi])/4,(3 \[Pi])/4}
{{-1,-1},(3 \[Pi])/4,(5 \[Pi])/4}
POSTED BY: Werner Geiger
Posted 2 years ago

Meanwhile I found out that the symbolic result of PlanarAngle is wrong. The correct symbolic result of PlanarAngle would have to be a Piecewise expression that depends on the relative positions of the points p, q1, q2.

See the following and attached Notebook "210717b PlanarAngle Issues 2.nb".

Attachments:
POSTED BY: Werner Geiger
Posted 2 years ago

Your findings are touched upon in the PlanarAngle documentation

enter image description here

POSTED BY: Hans Milton
Posted 2 years ago

Hans, you're right. I didn't really realize what "generic" means.

However, that makes the symbolic result of PlanarAngle pretty meaningless.

POSTED BY: Werner Geiger
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract