-1

when I tried to calculate the homogeneous matrix in two different ways, there was a very small
discrepency, 0 and 0.000000000000000061229677524420688 are in the same location of the two matrice.
The number 0.000000000000000061229677524420688 is extremely close to 0, so I take them as exactly
the same number. I though if I plug then into Atan2(,), the answers should be the same.
But unexpectedly, the answer are totally different. Here is the code segment:

         Dim b = Atan2(0.000000000000000061229677524420688, 0)
         Dim c = Atan2(0, 0)

After I run the code in compliler, b is 1.57096, c is 0.

Liu
  • 413
  • 4
  • 11
  • This is the expected behavior of the function atan2, though it could raise an error for (0, 0). But it is pathological to have to compute atan2 for such arguments, you should question your method/algorithm/program. –  Jan 22 '22 at 15:57

1 Answers1

1

Your atan2 arguments are not valid in math sense, this function is not defined for both zeros.

Note that first argument should be r*sin(fi), the second one - r*cos(fi) for some angle fi and r>0

In dotnet rules are - note they assign 0in the 4th case, while one might expect NaN or some error:

For points on the boundaries of the quadrants, the return value is the following:

If y is 0 and x is not negative, θ = 0.
If y is 0 and x is negative, θ = π.
If y is positive and x is 0, θ = π/2.
If y is negative and x is 0, θ = -π/2.
If y is 0 and x is 0, θ = 0.

Your values fit to 5th and 3rd cases

MBo
  • 77,366
  • 5
  • 53
  • 86
  • Does the rule still applies in other languages? – Liu Jan 22 '22 at 15:24
  • Mostly yes. C language function work similar, Intel x87 FPATAN instruction provides such behaviour - so this is common way. But I cannot say about all languages and implementations. (look at the section 7 of Wiki page) – MBo Jan 22 '22 at 17:52