Liu
Liu

Reputation: 433

Atan2 Precision Problems

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.

Upvotes: -1

Views: 526

Answers (1)

MBo
MBo

Reputation: 80187

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

Upvotes: 1

Related Questions